From 08ca3e26a8feb0353a960b6b6d20ccb2755db8af Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 6 May 2014 13:16:05 +0200 Subject: [PATCH] lib/timeutils: remove get_boot_time from libcommon clock_gettime() needs -lrt, so let's keep this stuff outside libcommon.la Reported-by: Ruediger Meier Signed-off-by: Karel Zak --- include/Makemodule.am | 1 + include/timeutils.h | 1 - lib/timeutils.c | 26 -------------------------- login-utils/Makemodule.am | 4 ++-- login-utils/last.c | 1 + sys-utils/Makemodule.am | 2 +- sys-utils/dmesg.c | 1 + 7 files changed, 6 insertions(+), 30 deletions(-) diff --git a/include/Makemodule.am b/include/Makemodule.am index 2cc9fb5af..7f461c6fe 100644 --- a/include/Makemodule.am +++ b/include/Makemodule.am @@ -4,6 +4,7 @@ dist_noinst_HEADERS += \ include/at.h \ include/bitops.h \ include/blkdev.h \ + include/boottime.h \ include/c.h \ include/canonicalize.h \ include/carefulputc.h \ diff --git a/include/timeutils.h b/include/timeutils.h index b9ba0f783..bcae6137c 100644 --- a/include/timeutils.h +++ b/include/timeutils.h @@ -51,6 +51,5 @@ 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 */ diff --git a/lib/timeutils.c b/lib/timeutils.c index d542c2f27..b811041e4 100644 --- a/lib/timeutils.c +++ b/lib/timeutils.c @@ -340,29 +340,3 @@ 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; -} diff --git a/login-utils/Makemodule.am b/login-utils/Makemodule.am index aca028a29..49fde4544 100644 --- a/login-utils/Makemodule.am +++ b/login-utils/Makemodule.am @@ -4,8 +4,8 @@ usrbin_exec_PROGRAMS += last dist_man_MANS += \ login-utils/last.1 \ login-utils/lastb.1 -last_SOURCES = login-utils/last.c lib/strutils.c -last_LDADD = $(LDADD) libcommon.la +last_SOURCES = login-utils/last.c lib/boottime.c +last_LDADD = $(LDADD) libcommon.la -lrt install-exec-hook-last: cd $(DESTDIR)$(usrbin_execdir) && ln -sf last lastb diff --git a/login-utils/last.c b/login-utils/last.c index ed1058652..7848dd0da 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -50,6 +50,7 @@ #include "carefulputc.h" #include "strutils.h" #include "timeutils.h" +#include "boottime.h" #if defined(_HAVE_UT_TV) # define UL_UT_TIME ut_tv.tv_sec diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am index a19d58b84..eb78176cc 100644 --- a/sys-utils/Makemodule.am +++ b/sys-utils/Makemodule.am @@ -70,7 +70,7 @@ if LINUX # bin_PROGRAMS += dmesg dist_man_MANS += sys-utils/dmesg.1 -dmesg_SOURCES = sys-utils/dmesg.c +dmesg_SOURCES = sys-utils/dmesg.c lib/boottime.c dmesg_LDADD = $(LDADD) libcommon.la -lrt sbin_PROGRAMS += ctrlaltdel diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index 3d58623c2..73b246e0b 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -33,6 +33,7 @@ #include "closestream.h" #include "optutils.h" #include "timeutils.h" +#include "boottime.h" #include "mangle.h" #include "pager.h"