]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: warn on boot time failure instead of suppressing timestamps
authorKarel Zak <kzak@redhat.com>
Thu, 12 Mar 2026 12:22:55 +0000 (13:22 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 12 Mar 2026 12:22:55 +0000 (13:22 +0100)
When dmesg_get_boot_time() fails, warn the user instead of silently
adding DMESG_TIMEFTM_NONE to suppress all timestamp output. The user
asked for a specific format and should get it, with a warning that
wall-clock timestamps may be inaccurate.

Also move the boot time check after the time format post-processing
so it operates on the final resolved format list, and add
DMESG_TIMEFTM_CTIME_DELTA to the condition since it also requires
boot time.

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/dmesg.c

index 1440dd4e4c34ee6b8d81be8a2c81d38f6337fb69..41907717877e5c368d717801064c438da31522bf 100644 (file)
@@ -1889,17 +1889,6 @@ int main(int argc, char *argv[])
                nopager = 1;
        }
 
-       if ((is_time_fmt_set(&ctl, DMESG_TIMEFTM_RELTIME) ||
-            is_time_fmt_set(&ctl, DMESG_TIMEFTM_CTIME)   ||
-            is_time_fmt_set(&ctl, DMESG_TIMEFTM_ISO8601)) ||
-            ctl.since ||
-            ctl.until) {
-               if (dmesg_get_boot_time(&ctl.boot_time) != 0)
-                       include_time_fmt(&ctl, DMESG_TIMEFTM_NONE);
-               else
-                       ctl.suspended_time = dmesg_get_suspended_time();
-       }
-
        /*
         * Resolve NONE (--notime) vs. delta combinations. When both are
         * specified (e.g. -d -t), delta wins and timestamp is suppressed.
@@ -1934,6 +1923,20 @@ int main(int argc, char *argv[])
                                          DMESG_TIMEFTM_CTIME, DMESG_TIMEFTM_CTIME_DELTA);
        }
 
+       /* Boot time is needed for wall-clock timestamp formats */
+       if ((is_time_fmt_set(&ctl, DMESG_TIMEFTM_RELTIME)     ||
+            is_time_fmt_set(&ctl, DMESG_TIMEFTM_CTIME)       ||
+            is_time_fmt_set(&ctl, DMESG_TIMEFTM_CTIME_DELTA) ||
+            is_time_fmt_set(&ctl, DMESG_TIMEFTM_ISO8601))    ||
+            ctl.since ||
+            ctl.until) {
+               if (dmesg_get_boot_time(&ctl.boot_time) != 0)
+                       warnx(_("failed to determine boot time, "
+                               "timestamps will be inaccurate"));
+               else
+                       ctl.suspended_time = dmesg_get_suspended_time();
+       }
+
        if (!ctl.json)
                ctl.color = colors_init(colormode, "dmesg") ? 1 : 0;
        if (ctl.follow)