summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--disk-utils/fsck.cramfs.c8
-rw-r--r--include/monotonic.h6
-rw-r--r--include/timeutils.h3
-rw-r--r--lib/monotonic.c6
-rw-r--r--lib/timeutils.c27
-rw-r--r--sys-utils/Makemodule.am4
-rw-r--r--sys-utils/hwclock-rtc.c5
7 files changed, 32 insertions, 27 deletions
diff --git a/disk-utils/fsck.cramfs.c b/disk-utils/fsck.cramfs.c
index 0d9bdadf7..76ed303b0 100644
--- a/disk-utils/fsck.cramfs.c
+++ b/disk-utils/fsck.cramfs.c
@@ -42,7 +42,6 @@
#include <errno.h>
#include <string.h>
#include <getopt.h>
-#include <utime.h>
#include <fcntl.h>
/* We don't use our include/crc32.h, but crc32 from zlib!
@@ -52,6 +51,7 @@
*/
#include <zlib.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
@@ -419,7 +419,7 @@ static void do_uncompress(char *path, int outfd, unsigned long offset,
static void change_file_status(char *path, struct cramfs_inode *i)
{
- struct utimbuf epoch = { 0, 0 };
+ const struct timeval epoch = { 0, 0 };
if (euid == 0) {
if (lchown(path, i->uid, i->gid) < 0)
@@ -431,8 +431,8 @@ static void change_file_status(char *path, struct cramfs_inode *i)
}
if (S_ISLNK(i->mode))
return;
- if (utime(path, &epoch) < 0)
- err(FSCK_EX_ERROR, _("utime failed: %s"), path);
+ if (utimes(path, &epoch) < 0)
+ err(FSCK_EX_ERROR, _("utimes failed: %s"), path);
}
static void do_directory(char *path, struct cramfs_inode *i)
diff --git a/include/monotonic.h b/include/monotonic.h
index a499fa34a..296173ece 100644
--- a/include/monotonic.h
+++ b/include/monotonic.h
@@ -1,6 +1,12 @@
#ifndef UTIL_LINUX_MONOTONIC_H
#define UTIL_LINUX_MONOTONIC_H
+# ifdef CLOCK_MONOTONIC_RAW
+# define UL_CLOCK_MONOTONIC CLOCK_MONOTONIC_RAW
+# else
+# define UL_CLOCK_MONOTONIC CLOCK_MONOTONIC
+# endif
+
#include <sys/time.h>
extern int get_boot_time(struct timeval *boot_time);
diff --git a/include/timeutils.h b/include/timeutils.h
index 230e6db5f..95f1b44da 100644
--- a/include/timeutils.h
+++ b/include/timeutils.h
@@ -82,9 +82,6 @@ int strtime_iso(const time_t *t, int flags, char *buf, size_t bufsz);
#define UL_SHORTTIME_THISYEAR_HHMM (1 << 1)
-int time_is_today(const time_t *t, struct timeval *now);
-int time_is_thisyear(const time_t *t, struct timeval *now);
-
int strtime_short(const time_t *t, struct timeval *now, int flags, char *buf, size_t bufsz);
#ifndef HAVE_TIMEGM
diff --git a/lib/monotonic.c b/lib/monotonic.c
index bb58e15d7..96ead1ee0 100644
--- a/lib/monotonic.c
+++ b/lib/monotonic.c
@@ -52,12 +52,8 @@ int gettime_monotonic(struct timeval *tv)
int ret;
struct timespec ts;
-# ifdef CLOCK_MONOTONIC_RAW
/* Linux specific, can't slew */
- if (!(ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts))) {
-# else
- if (!(ret = clock_gettime(CLOCK_MONOTONIC, &ts))) {
-# endif
+ if (!(ret = clock_gettime(UL_CLOCK_MONOTONIC, &ts))) {
tv->tv_sec = ts.tv_sec;
tv->tv_usec = ts.tv_nsec / 1000;
}
diff --git a/lib/timeutils.c b/lib/timeutils.c
index 9c286aebc..d403ced90 100644
--- a/lib/timeutils.c
+++ b/lib/timeutils.c
@@ -503,34 +503,37 @@ int strtime_iso(const time_t *t, int flags, char *buf, size_t bufsz)
}
/* relative time functions */
-int time_is_today(const time_t *t, struct timeval *now)
+static inline int time_is_thisyear(struct tm const *const tm,
+ struct tm const *const tmnow)
{
- if (now->tv_sec == 0)
- gettimeofday(now, NULL);
- return *t / (3600 * 24) == now->tv_sec / (3600 * 24);
+ return tm->tm_year == tmnow->tm_year;
}
-int time_is_thisyear(const time_t *t, struct timeval *now)
+static inline int time_is_today(struct tm const *const tm,
+ struct tm const *const tmnow)
{
- if (now->tv_sec == 0)
- gettimeofday(now, NULL);
- return *t / (3600 * 24 * 365) == now->tv_sec / (3600 * 24 * 365);
+ return (tm->tm_yday == tmnow->tm_yday &&
+ time_is_thisyear(tm, tmnow));
}
int strtime_short(const time_t *t, struct timeval *now, int flags, char *buf, size_t bufsz)
{
- struct tm tm;
+ struct tm tm, tmnow;
int rc = 0;
- localtime_r(t, &tm);
+ if (now->tv_sec == 0)
+ gettimeofday(now, NULL);
+
+ localtime_r(t, &tm);
+ localtime_r(&now->tv_sec, &tmnow);
- if (time_is_today(t, now)) {
+ if (time_is_today(&tm, &tmnow)) {
rc = snprintf(buf, bufsz, "%02d:%02d", tm.tm_hour, tm.tm_min);
if (rc < 0 || (size_t) rc > bufsz)
return -1;
rc = 1;
- } else if (time_is_thisyear(t, now)) {
+ } else if (time_is_thisyear(&tm, &tmnow)) {
if (flags & UL_SHORTTIME_THISYEAR_HHMM)
rc = strftime(buf, bufsz, "%b%d/%H:%M", &tm);
else
diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am
index 825a7335b..fdecbfac4 100644
--- a/sys-utils/Makemodule.am
+++ b/sys-utils/Makemodule.am
@@ -454,7 +454,9 @@ hwclock_SOURCES = \
sys-utils/hwclock.h \
sys-utils/hwclock-cmos.c
if LINUX
-hwclock_SOURCES += sys-utils/hwclock-rtc.c
+hwclock_SOURCES += \
+ sys-utils/hwclock-rtc.c \
+ lib/monotonic.c
endif
hwclock_LDADD = $(LDADD) libcommon.la -lm
if HAVE_AUDIT
diff --git a/sys-utils/hwclock-rtc.c b/sys-utils/hwclock-rtc.c
index 32feb3504..a0d28f89e 100644
--- a/sys-utils/hwclock-rtc.c
+++ b/sys-utils/hwclock-rtc.c
@@ -12,6 +12,7 @@
#include <time.h>
#include <unistd.h>
+#include "monotonic.h"
#include "nls.h"
#include "hwclock.h"
@@ -223,12 +224,12 @@ static int busywait_for_rtc_clock_tick(const struct hwclock_control *ctl,
* something weird happens, we have a time limit (1.5s) on this loop
* to reduce the impact of this failure.
*/
- gettimeofday(&begin, NULL);
+ gettime_monotonic(&begin);
do {
rc = do_rtc_read_ioctl(rtc_fd, &nowtime);
if (rc || start_time.tm_sec != nowtime.tm_sec)
break;
- gettimeofday(&now, NULL);
+ gettime_monotonic(&now);
if (time_diff(now, begin) > 1.5) {
warnx(_("Timed out waiting for time change."));
return 1;