X-Git-Url: https://unix4lyfe.org/gitweb/darkstat/blobdiff_plain/1b1591ab5dc81e7aa2cb2665d034572f5157e0e1..0736c704e88399324e1a3c5d484cb116458c23b1:/daylog.c diff --git a/daylog.c b/daylog.c index d443dcf..080f11f 100644 --- a/daylog.c +++ b/daylog.c @@ -1,5 +1,5 @@ /* darkstat 3 - * copyright (c) 2007-2011 Emil Mikulic. + * copyright (c) 2007-2014 Emil Mikulic. * * daylog.c: daily usage log * @@ -9,6 +9,7 @@ #define _GNU_SOURCE 1 /* for O_NOFOLLOW on Linux */ +#include "cdefs.h" #include "err.h" #include "daylog.h" #include "str.h" @@ -23,7 +24,7 @@ #include static const char *daylog_fn = NULL; -static long today_real, tomorrow_real; +static time_t today_real, tomorrow_real; static uint64_t bytes_in, bytes_out, pkts_in, pkts_out; #define DAYLOG_DATE_LEN 26 /* strlen("1900-01-01 00:00:00 +1234") + 1 */ @@ -55,6 +56,7 @@ static time_t tomorrow(time_t t_before) { } /* Warns on error. */ +static void daylog_write(const char *format, ...) _printflike_(1, 2); static void daylog_write(const char *format, ...) { int fd; ssize_t wr; @@ -86,28 +88,33 @@ static void daylog_write(const char *format, ...) { } static void daylog_emit(void) { - daylog_write("%s|%ld|%qu|%qu|%qu|%qu\n", - fmt_date(today_real), (long)today_real, - bytes_in, bytes_out, pkts_in, pkts_out); + daylog_write("%s|%qu|%qu|%qu|%qu|%qu\n", + fmt_date(today_real), + (qu)today_real, + (qu)bytes_in, + (qu)bytes_out, + (qu)pkts_in, + (qu)pkts_out); } void daylog_init(const char *filename) { daylog_fn = filename; today_real = now_real(); tomorrow_real = tomorrow(today_real); - verbosef("today is %ld, tomorrow is %ld", - (long)today_real, (long)tomorrow_real); + verbosef("today is %llu, tomorrow is %llu", + (llu)today_real, + (llu)tomorrow_real); bytes_in = bytes_out = pkts_in = pkts_out = 0; - daylog_write("# logging started at %s (%ld)\n", - fmt_date(today_real), (long)today_real); + daylog_write("# logging started at %s (%qu)\n", + fmt_date(today_real), (qu)today_real); } void daylog_free(void) { today_real = now_real(); daylog_emit(); /* Emit what's currently accumulated before we exit. */ - daylog_write("# logging stopped at %s (%ld)\n", - fmt_date(today_real), (long)today_real); + daylog_write("# logging stopped at %s (%qu)\n", + fmt_date(today_real), (qu)today_real); } void daylog_acct(uint64_t amount, enum graph_dir dir) { @@ -121,7 +128,7 @@ void daylog_acct(uint64_t amount, enum graph_dir dir) { today_real = now_real(); tomorrow_real = tomorrow(today_real); bytes_in = bytes_out = pkts_in = pkts_out = 0; - verbosef("updated daylog, tomorrow = %ld", (long)tomorrow_real); + verbosef("updated daylog, tomorrow = %llu", (llu)tomorrow_real); } /* Accounting. */