use UTC time when logging
authorAlexey Chernobaev <achernobaev@dev.rtsoft.ru>
Wed, 29 Aug 2018 18:39:06 +0000 (21:39 +0300)
committerAleksei Vereshchagin <avereschagin@dev.rtsoft.ru>
Mon, 3 Sep 2018 15:21:42 +0000 (18:21 +0300)
profctl.c

index fc6fc16cddb8f76c0812c6ee6b8fa4fe3b9a1400..031f60b794679b061882c3090fba0134daa7a28b 100644 (file)
--- 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]);