summaryrefslogtreecommitdiffstats
path: root/sys-utils/dmesg.c
diff options
context:
space:
mode:
authorKarel Zak2015-03-23 11:40:59 +0100
committerKarel Zak2015-03-23 11:40:59 +0100
commit5a34fb8a07de1716ca866832fa284b53109dee79 (patch)
tree0ffdaa5eb8fa7cf0934fab3df339446ed7750424 /sys-utils/dmesg.c
parentlogger: fix LOGGER_TEST_TIMEOFDAY check (diff)
downloadkernel-qcow2-util-linux-5a34fb8a07de1716ca866832fa284b53109dee79.tar.gz
kernel-qcow2-util-linux-5a34fb8a07de1716ca866832fa284b53109dee79.tar.xz
kernel-qcow2-util-linux-5a34fb8a07de1716ca866832fa284b53109dee79.zip
dmesg: use GMT in tests, add DMESG_TEST_BOOTIME
We don't want to hardcode anything to the test, just use env.variable DMESG_TEST_BOOTIME. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/dmesg.c')
-rw-r--r--sys-utils/dmesg.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index a17cc70af..54612f5b1 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -1193,6 +1193,24 @@ static int which_time_format(const char *optarg)
errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);
}
+#ifdef TEST_DMESG
+static inline int dmesg_get_boot_time(struct timeval *tv)
+{
+ char *str = getenv("DMESG_TEST_BOOTIME");
+ uintmax_t sec, usec;
+
+ if (str && sscanf(str, "%ju.%ju", &sec, &usec) == 2) {
+ tv->tv_sec = sec;
+ tv->tv_usec = usec;
+ return tv->tv_sec >= 0 && tv->tv_usec >= 0 ? 0 : -EINVAL;
+ }
+
+ return get_boot_time(tv);
+}
+#else
+# define dmesg_get_boot_time get_boot_time
+#endif
+
int main(int argc, char *argv[])
{
char *buf = NULL;
@@ -1377,14 +1395,8 @@ int main(int argc, char *argv[])
if (is_timefmt(&ctl, RELTIME) ||
is_timefmt(&ctl, CTIME) ||
is_timefmt(&ctl, ISO8601)) {
-
-#ifdef TEST_DMESG
- ctl.boot_time.tv_sec = 1234567890;
- ctl.boot_time.tv_usec = 123456;
-#else
- if (get_boot_time(&ctl.boot_time) != 0)
+ if (dmesg_get_boot_time(&ctl.boot_time) != 0)
ctl.time_fmt = DMESG_TIMEFTM_NONE;
-#endif
}
if (delta)