From: Karel Zak Date: Thu, 12 Mar 2026 12:22:55 +0000 (+0100) Subject: dmesg: warn on boot time failure instead of suppressing timestamps X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b35816ab92e2ea01fb334199165bb6b7b9d09a2;p=thirdparty%2Futil-linux.git dmesg: warn on boot time failure instead of suppressing timestamps 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 --- diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index 1440dd4e4..419077178 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -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)