]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: fix -d -t (--show-delta --notime) output regression
authorKarel Zak <kzak@redhat.com>
Thu, 12 Mar 2026 11:56:14 +0000 (12:56 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 12 Mar 2026 11:56:14 +0000 (12:56 +0100)
When -d and -t are used together, only the time delta should be
printed without the timestamp prefix. This was broken because
DMESG_TIMEFTM_NONE in the format list caused the print_record()
loop to break early before processing the delta format.

Resolve the conflict after option parsing: when NONE coexists with
a delta format (TIME_DELTA or DELTA), replace all formats with just
DELTA. When NONE is used without delta, it suppresses all timestamps
as before.

Fixes: https://github.com/util-linux/util-linux/issues/4110
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/dmesg.c

index f4ff3e2c5782a9b3ce7e2cbb7a28d7e6e6c7e037..5496bdbe4fdfa611fd92e4e77affa5ff814b6278 100644 (file)
@@ -1879,6 +1879,24 @@ int main(int argc, char *argv[])
                        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.
+        * When NONE is used without delta, it suppresses all timestamps.
+        */
+       if (is_time_fmt_set(&ctl, DMESG_TIMEFTM_NONE)) {
+               if (is_time_fmt_set(&ctl, DMESG_TIMEFTM_TIME_DELTA)
+                   || is_time_fmt_set(&ctl, DMESG_TIMEFTM_DELTA)) {
+                       reset_time_fmts(&ctl);
+                       ctl.ntime_fmts = 0;
+                       include_time_fmt(&ctl, DMESG_TIMEFTM_DELTA);
+               } else {
+                       reset_time_fmts(&ctl);
+                       ctl.ntime_fmts = 0;
+                       include_time_fmt(&ctl, DMESG_TIMEFTM_NONE);
+               }
+       }
+
        /* -d uses TIME_DELTA; merge with -T (CTIME) if both specified */
        if (is_time_fmt_set(&ctl, DMESG_TIMEFTM_TIME_DELTA)
            && is_time_fmt_set(&ctl, DMESG_TIMEFTM_CTIME)) {