]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: move get_boot_time() to lib/timeutils
authorSami Kerola <kerolasa@iki.fi>
Wed, 23 Apr 2014 21:59:29 +0000 (22:59 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sun, 4 May 2014 10:42:03 +0000 (11:42 +0100)
In future the last(1) will use get_boot_time() as well.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
include/timeutils.h
lib/timeutils.c
sys-utils/dmesg.c

index bcae6137cfdcaa8b85cc74e4480440d665266925..b9ba0f78320eb547b7f722b90563203089a93ee0 100644 (file)
@@ -51,5 +51,6 @@ typedef uint64_t nsec_t;
 #define FORMAT_TIMESPAN_MAX 64
 
 int parse_timestamp(const char *t, usec_t *usec);
+int get_boot_time(struct timeval *boot_time);
 
 #endif /* UTIL_LINUX_TIME_UTIL_H */
index 7fe62187df239c1267f2017e3280b6142f8f1635..c1b632e0a0aa9236a9046ccc7e75903352841178 100644 (file)
 #include <assert.h>
 #include <ctype.h>
 #include <string.h>
+#include <sys/sysinfo.h>
+#include <sys/time.h>
 #include <time.h>
 
 #include "c.h"
+#include "nls.h"
 #include "strutils.h"
 #include "timeutils.h"
 
@@ -336,3 +339,29 @@ int parse_timestamp(const char *t, usec_t *usec)
 
        return 0;
 }
+
+int get_boot_time(struct timeval *boot_time)
+{
+       struct timespec hires_uptime;
+       struct timeval lores_uptime, now;
+       struct sysinfo info;
+
+       if (gettimeofday(&now, NULL) != 0) {
+               warn(_("gettimeofday failed"));
+               return -errno;
+       }
+#ifdef CLOCK_BOOTTIME
+       if (clock_gettime(CLOCK_BOOTTIME, &hires_uptime) == 0) {
+               TIMESPEC_TO_TIMEVAL(&lores_uptime, &hires_uptime);
+               timersub(&now, &lores_uptime, boot_time);
+               return 0;
+       }
+#endif
+       /* fallback */
+       if (sysinfo(&info) != 0)
+               warn(_("sysinfo failed"));
+
+       boot_time->tv_sec = now.tv_sec - info.uptime;
+       boot_time->tv_usec = 0;
+       return 0;
+}
index df68c8440442fe231d83772da3f7499f5057175b..196cc61ea2277dc1685bc5ddd9e8d5f0e33bbfa5 100644 (file)
@@ -472,33 +472,6 @@ static int get_syslog_buffer_size(void)
        return n > 0 ? n : 0;
 }
 
-static int get_boot_time(struct timeval *boot_time)
-{
-       struct timespec hires_uptime;
-       struct timeval lores_uptime, now;
-       struct sysinfo info;
-
-       if (gettimeofday(&now, NULL) != 0) {
-               warn(_("gettimeofday failed"));
-               return -errno;
-       }
-
-#ifdef CLOCK_BOOTTIME
-       if (clock_gettime(CLOCK_BOOTTIME, &hires_uptime) == 0) {
-               TIMESPEC_TO_TIMEVAL(&lores_uptime, &hires_uptime);
-               timersub(&now, &lores_uptime, boot_time);
-               return 0;
-       }
-#endif
-       /* fallback */
-       if (sysinfo(&info) != 0)
-               warn(_("sysinfo failed"));
-
-       boot_time->tv_sec = now.tv_sec - info.uptime;
-       boot_time->tv_usec = 0;
-       return 0;
-}
-
 /*
  * Reads messages from regular file by mmap
  */