]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/monotonic: get_suspended_time: use usec_t
authorThomas Weißschuh <thomas@t-8ch.de>
Sat, 21 Jan 2023 00:21:10 +0000 (00:21 +0000)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 24 Jan 2023 16:04:48 +0000 (16:04 +0000)
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
include/monotonic.h
lib/monotonic.c
sys-utils/dmesg.c

index 380e59c3791ef32f9e17eaa903cf645f9b9c81fa..5c5c2c1c114fafaf594c2333346a38ba40a9bbbb 100644 (file)
 
 #include <sys/time.h>
 
+#include "timeutils.h"
+
 extern int get_boot_time(struct timeval *boot_time);
 
-extern time_t get_suspended_time(void);
+extern usec_t get_suspended_time(void);
 
 extern int gettime_monotonic(struct timeval *tv);
 
index f0aeba6828e781747abbfac626fabf6d44d7fb7d..cd554dd7193374df34ce33a718a062d1b3784153 100644 (file)
@@ -48,14 +48,14 @@ int get_boot_time(struct timeval *boot_time)
 #endif
 }
 
-time_t get_suspended_time(void)
+usec_t get_suspended_time(void)
 {
 #if defined(CLOCK_BOOTTIME) && defined(CLOCK_MONOTONIC)
        struct timespec boot, mono;
 
        if (clock_gettime(CLOCK_BOOTTIME, &boot) == 0 &&
            clock_gettime(CLOCK_MONOTONIC, &mono) == 0)
-               return boot.tv_sec - mono.tv_sec;
+               return timespec_to_usec(&boot) - timespec_to_usec(&mono);
 #endif
        return 0;
 }
index 42000cb40e251ccaea26cfc3487471595806f859..6bd6880adb11ed05838765b152879a1259fde4dd 100644 (file)
@@ -170,7 +170,7 @@ struct dmesg_control {
        struct timeval  lasttime;       /* last printed timestamp */
        struct tm       lasttm;         /* last localtime */
        struct timeval  boot_time;      /* system boot time */
-       time_t          suspended_time; /* time spent in suspended state */
+       usec_t          suspended_time; /* time spent in suspended state */
 
        int             action;         /* SYSLOG_ACTION_* */
        int             method;         /* DMESG_METHOD_* */
@@ -786,7 +786,7 @@ static int get_next_syslog_record(struct dmesg_control *ctl,
 
 static time_t record_time(struct dmesg_control *ctl, struct dmesg_record *rec)
 {
-       return ctl->boot_time.tv_sec + ctl->suspended_time + rec->tv.tv_sec;
+       return ctl->boot_time.tv_sec + ctl->suspended_time / USEC_PER_SEC + rec->tv.tv_sec;
 }
 
 static int accept_record(struct dmesg_control *ctl, struct dmesg_record *rec)
@@ -877,7 +877,7 @@ static char *iso_8601_time(struct dmesg_control *ctl, struct dmesg_record *rec,
                           char *buf, size_t bufsz)
 {
        struct timeval tv = {
-               .tv_sec = ctl->boot_time.tv_sec + ctl->suspended_time + rec->tv.tv_sec,
+               .tv_sec = ctl->boot_time.tv_sec + ctl->suspended_time / USEC_PER_SEC + rec->tv.tv_sec,
                .tv_usec = rec->tv.tv_usec
        };
 
@@ -1355,7 +1355,7 @@ static inline int dmesg_get_boot_time(struct timeval *tv)
        return get_boot_time(tv);
 }
 
-static inline time_t dmesg_get_suspended_time(void)
+static inline usec_t dmesg_get_suspended_time(void)
 {
        if (getenv("DMESG_TEST_BOOTIME"))
                return 0;