diff options
author | John Denker <jsd@av8n.com> | 2012-07-19 21:09:20 -0700 |
---|---|---|
committer | John Denker <jsd@av8n.com> | 2012-07-29 15:32:34 -0700 |
commit | 3413e333fd7ac49461cfbc89839a2b7e94ac2d3a (patch) | |
tree | 18d0da71a5a69ebf0b6d5c8d0cce6e9558d5da0c | |
parent | 945767f12154698fab3e7e370486a5e9b09276e9 (diff) |
nicer formatting of ages
-rw-r--r-- | tools/greylist.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/tools/greylist.c b/tools/greylist.c index 3ba502d..613c1a4 100644 --- a/tools/greylist.c +++ b/tools/greylist.c @@ -11,6 +11,7 @@ #include <fstream> /* for ofstream() */ #include <fcntl.h> /* for creat() */ #include <sys/time.h> /* for gettimeofday() */ +#include <sstream> // requires apt-get install libboost-filesystem-dev: #include <boost/filesystem.hpp> @@ -67,6 +68,17 @@ public: void update(const string msg, const timeval new_mod, const timeval new_ac); }; +string time_out(const int ttt){ + int sec(ttt % 60); + int min((ttt / 60) % 60); + int hr(ttt / 3600); + stringstream foo; + foo << hr + << ":" << setw(2) << setfill('0') << min + << ":" << setw(2) << setfill('0') << sec; + return foo.str(); +} + void scan(const string p){ timeval now; gettimeofday(&now, NULL); @@ -88,12 +100,12 @@ void scan(const string p){ } int mod_age = now.tv_sec - mystat.st_mtime; int ac_age = now.tv_sec - mystat.st_atime; - cout << setw(10) << mod_age - << " " << setw(10) << ac_age; + cout << setw(10) << time_out(mod_age) + << " " << setw(10) << time_out(ac_age); if (mod_age < minimum_age) { cout << " young"; } else if (mod_age == ac_age) { - cout << " never used"; + cout << " unused"; } } cout << '\n'; @@ -109,8 +121,8 @@ void whatsit::update(const string msg, const timeval new_mod, const timeval new_ cerr << progname << ": " << msg << ": " << ipbase; if (hostname.length()) cerr << " " << hostname; - cerr << " mod_age: " << mod_age - << " ac_age: " << ac_age + cerr << " mod_age: " << time_out(mod_age) + << " ac_age: " << time_out(ac_age) << endl; timeval upd[2] = { // beware: access illogically comes *before* modification here: |