From 9bf5af4857f6230d4fff1e87a0cbcdbe92bf44c1 Mon Sep 17 00:00:00 2001 From: Alexey Chernobaev Date: Wed, 29 Aug 2018 21:39:06 +0300 Subject: [PATCH] use UTC time when logging --- profctl.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/profctl.c b/profctl.c index fc6fc16..031f60b 100644 --- a/profctl.c +++ b/profctl.c @@ -76,6 +76,26 @@ static struct option long_options[] = { {0, 0, 0, 0} }; +static void log_time_zone_info() +{ + time_t t = time(NULL); + struct tm tm = *localtime(&t); + fprintf(stderr, "Local time: %04d-%02d-%02d %02d:%02d:%02d. Time zone: %s (UTC", + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_zone); + char sign; + if (tm.tm_gmtoff >= 0) { + sign = '+'; + } + else { + sign = '-'; + tm.tm_gmtoff = -tm.tm_gmtoff; + } + int minutes = tm.tm_gmtoff / 60; + fprintf(stderr, "%c%02d%02d). ", sign, minutes / 60, minutes % 60); + fprintf(stderr, "Using UTC time in the log\n"); +} + +// et: epoch time; tm: UTC time (broken-down representation); millisec: milliseconds static int get_current_time(time_t *et, struct tm *tm, int *millisec) { struct timeval timeval; @@ -97,7 +117,7 @@ static int get_current_time(time_t *et, struct tm *tm, int *millisec) *et = t; } if (tm != NULL) { - *tm = *localtime(&t); + *tm = *gmtime(&t); } *millisec = msec; return result; @@ -729,6 +749,7 @@ int main(int argc, char **argv) if (verbose) { log_error("=== started ==="); + log_time_zone_info(); int i; for (i = 0; i < argc; i++) { fprintf(stderr, "argv[%d] = %s\n", i, argv[i]); -- 2.7.4