From: Karel Zak Date: Wed, 19 Nov 2014 10:54:47 +0000 (+0100) Subject: build-sys: move all around clock_gettime() to monotonic.c X-Git-Tag: v2.26-rc1~196 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cd2876d252215fb3fbe46f787cb37cd4fbd64e53;p=thirdparty%2Futil-linux.git build-sys: move all around clock_gettime() to monotonic.c Signed-off-by: Karel Zak --- diff --git a/include/Makemodule.am b/include/Makemodule.am index d162d24b4e..c4a52e4cf3 100644 --- a/include/Makemodule.am +++ b/include/Makemodule.am @@ -4,7 +4,7 @@ dist_noinst_HEADERS += \ include/at.h \ include/bitops.h \ include/blkdev.h \ - include/boottime.h \ + include/monotonic.h \ include/c.h \ include/canonicalize.h \ include/carefulputc.h \ diff --git a/include/boottime.h b/include/monotonic.h similarity index 80% rename from include/boottime.h rename to include/monotonic.h index f1d0d0b277..f3b03d3d00 100644 --- a/include/boottime.h +++ b/include/monotonic.h @@ -6,4 +6,6 @@ */ extern int get_boot_time(struct timeval *boot_time); +extern int gettime_monotonic(struct timeval *tv); + #endif /* UTIL_LINUX_BOOTTIME_H */ diff --git a/include/timeutils.h b/include/timeutils.h index 97f054489e..8ed501b9db 100644 --- a/include/timeutils.h +++ b/include/timeutils.h @@ -53,6 +53,4 @@ typedef uint64_t nsec_t; int parse_timestamp(const char *t, usec_t *usec); -int gettime_monotonic(struct timeval *tv); - #endif /* UTIL_LINUX_TIME_UTIL_H */ diff --git a/lib/boottime.c b/lib/monotonic.c similarity index 57% rename from lib/boottime.c rename to lib/monotonic.c index f9366bd33c..3d4a4438e0 100644 --- a/lib/boottime.c +++ b/lib/monotonic.c @@ -1,11 +1,14 @@ - +/* + * Please, don't add this file to libcommon because clock_gettime() requires + * -lrt on systems with old libc. + */ #include #include #include #include "c.h" #include "nls.h" -#include "boottime.h" +#include "monotonic.h" int get_boot_time(struct timeval *boot_time) { @@ -41,3 +44,25 @@ int get_boot_time(struct timeval *boot_time) return -ENOSYS; #endif } + +int gettime_monotonic(struct timeval *tv) +{ +#ifdef CLOCK_MONOTONIC + /* Can slew only by ntp and adjtime */ + int ret; + struct timespec ts; + +# ifdef CLOCK_MONOTONIC_RAW + /* Linux specific, cant slew */ + if (!(ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts))) { +# else + if (!(ret = clock_gettime(CLOCK_MONOTONIC, &ts))) { +# endif + tv->tv_sec = ts.tv_sec; + tv->tv_usec = ts.tv_nsec / 1000; + } + return ret; +#else + return gettimeofday(tv, NULL); +#endif +} diff --git a/lib/timeutils.c b/lib/timeutils.c index bd3d402488..b811041e45 100644 --- a/lib/timeutils.c +++ b/lib/timeutils.c @@ -340,26 +340,3 @@ int parse_timestamp(const char *t, usec_t *usec) return 0; } - - -int gettime_monotonic(struct timeval *tv) -{ -#ifdef CLOCK_MONOTONIC - /* Can slew only by ntp and adjtime */ - int ret; - struct timespec ts; - -# ifdef CLOCK_MONOTONIC_RAW - /* Linux specific, cant slew */ - if (!(ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts))) { -# else - if (!(ret = clock_gettime(CLOCK_MONOTONIC, &ts))) { -# endif - tv->tv_sec = ts.tv_sec; - tv->tv_usec = ts.tv_nsec / 1000; - } - return ret; -#else - return gettimeofday(tv, NULL); -#endif -} diff --git a/libmount/src/Makemodule.am b/libmount/src/Makemodule.am index 9b0eadefbb..cc4ab22f4a 100644 --- a/libmount/src/Makemodule.am +++ b/libmount/src/Makemodule.am @@ -6,6 +6,7 @@ nodist_mountinc_HEADERS = $(top_builddir)/libmount/src/libmount.h usrlib_exec_LTLIBRARIES += libmount.la libmount_la_SOURCES = \ include/list.h \ + lib/monotonic.c \ \ libmount/src/cache.c \ libmount/src/fs.c \ diff --git a/libmount/src/lock.c b/libmount/src/lock.c index 0a07e9b032..a940a0e690 100644 --- a/libmount/src/lock.c +++ b/libmount/src/lock.c @@ -25,7 +25,7 @@ #include "closestream.h" #include "pathnames.h" #include "mountP.h" -#include "timeutils.h" +#include "monotonic.h" /* * lock handler diff --git a/login-utils/Makemodule.am b/login-utils/Makemodule.am index 73fc761d55..34c5fb4247 100644 --- a/login-utils/Makemodule.am +++ b/login-utils/Makemodule.am @@ -4,7 +4,7 @@ usrbin_exec_PROGRAMS += last dist_man_MANS += \ login-utils/last.1 \ login-utils/lastb.1 -last_SOURCES = login-utils/last.c lib/boottime.c +last_SOURCES = login-utils/last.c lib/monotonic.c last_LDADD = $(LDADD) libcommon.la $(CLOCKGETTIME_LIBS) install-exec-hook-last: diff --git a/login-utils/last.c b/login-utils/last.c index 54d9e1f8e3..bf2c2da329 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -50,7 +50,7 @@ #include "carefulputc.h" #include "strutils.h" #include "timeutils.h" -#include "boottime.h" +#include "monotonic.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 50d3eb3a41..25e1ad7bfd 100644 --- a/sys-utils/Makemodule.am +++ b/sys-utils/Makemodule.am @@ -71,7 +71,7 @@ EXTRA_DIST += sys-utils/fstrim.timer if BUILD_DMESG bin_PROGRAMS += dmesg dist_man_MANS += sys-utils/dmesg.1 -dmesg_SOURCES = sys-utils/dmesg.c lib/boottime.c +dmesg_SOURCES = sys-utils/dmesg.c lib/monotonic.c dmesg_LDADD = $(LDADD) libcommon.la $(CLOCKGETTIME_LIBS) endif @@ -90,7 +90,7 @@ endif if BUILD_BLKDISCARD sbin_PROGRAMS += blkdiscard dist_man_MANS += sys-utils/blkdiscard.8 -blkdiscard_SOURCES = sys-utils/blkdiscard.c +blkdiscard_SOURCES = sys-utils/blkdiscard.c lib/monotonic.c blkdiscard_LDADD = $(LDADD) libcommon.la $(CLOCKGETTIME_LIBS) endif @@ -166,7 +166,7 @@ endif # BUILD_SETARCH if BUILD_EJECT usrbin_exec_PROGRAMS += eject -eject_SOURCES = sys-utils/eject.c +eject_SOURCES = sys-utils/eject.c lib/monotonic.c eject_LDADD = $(LDADD) libmount.la libcommon.la $(CLOCKGETTIME_LIBS) eject_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir) dist_man_MANS += sys-utils/eject.1 diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index 1a1ace4ab4..c6152d49ad 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -33,7 +33,7 @@ #include "closestream.h" #include "optutils.h" #include "timeutils.h" -#include "boottime.h" +#include "monotonic.h" #include "mangle.h" #include "pager.h" diff --git a/sys-utils/eject.c b/sys-utils/eject.c index 5a181644d2..0dfd301666 100644 --- a/sys-utils/eject.c +++ b/sys-utils/eject.c @@ -52,7 +52,7 @@ #include "xalloc.h" #include "pathnames.h" #include "sysfs.h" -#include "timeutils.h" +#include "monotonic.h" /* * sg_io_hdr_t driver_status -- see kernel include/scsi/scsi.h