From: Thomas Weißschuh Date: Fri, 20 Jan 2023 06:18:36 +0000 (+0000) Subject: dmesg: add subsecond granularity for --since and --until X-Git-Tag: v2.39-rc1~114^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d1e5764c55d329217503225f333497092a9ef329;p=thirdparty%2Futil-linux.git dmesg: add subsecond granularity for --since and --until Fixes #1708 Signed-off-by: Thomas Weißschuh --- diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index 6bd6880adb..fdf0f46314 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -181,8 +181,8 @@ struct dmesg_control { ssize_t kmsg_first_read;/* initial read() return code */ char kmsg_buf[BUFSIZ];/* buffer to read kmsg data */ - time_t since; /* filter records by time */ - time_t until; /* filter records by time */ + usec_t since; /* filter records by time */ + usec_t until; /* filter records by time */ /* * For the --file option we mmap whole file. The unnecessary (already @@ -784,9 +784,11 @@ static int get_next_syslog_record(struct dmesg_control *ctl, return 1; } -static time_t record_time(struct dmesg_control *ctl, struct dmesg_record *rec) +static usec_t record_time(struct dmesg_control *ctl, struct dmesg_record *rec) { - return ctl->boot_time.tv_sec + ctl->suspended_time / USEC_PER_SEC + rec->tv.tv_sec; + return timeval_to_usec(&ctl->boot_time) + + ctl->suspended_time + + timeval_to_usec(&rec->tv); } static int accept_record(struct dmesg_control *ctl, struct dmesg_record *rec) @@ -842,7 +844,7 @@ static struct tm *record_localtime(struct dmesg_control *ctl, struct dmesg_record *rec, struct tm *tm) { - time_t t = record_time(ctl, rec); + time_t t = record_time(ctl, rec) / USEC_PER_SEC; return localtime_r(&t, tm); } @@ -1554,18 +1556,14 @@ int main(int argc, char *argv[]) break; case OPT_SINCE: { - usec_t p; - if (parse_timestamp(optarg, &p) < 0) + if (parse_timestamp(optarg, &ctl.since) < 0) errx(EXIT_FAILURE, _("invalid time value \"%s\""), optarg); - ctl.since = (time_t) (p / 1000000); break; } case OPT_UNTIL: { - usec_t p; - if (parse_timestamp(optarg, &p) < 0) + if (parse_timestamp(optarg, &ctl.until) < 0) errx(EXIT_FAILURE, _("invalid time value \"%s\""), optarg); - ctl.until = (time_t) (p / 1000000); break; } case 'h': diff --git a/tests/expected/dmesg/limit b/tests/expected/dmesg/limit index 9dbbc4e62e..03569ab79e 100644 --- a/tests/expected/dmesg/limit +++ b/tests/expected/dmesg/limit @@ -1,3 +1,4 @@ +[ 1.000000] example[1] [ 8.000000] example[2] [ 27.000000] example[3] [ 64.000000] example[4] diff --git a/tests/ts/dmesg/limit b/tests/ts/dmesg/limit index 9772784a29..f3f9643f47 100755 --- a/tests/ts/dmesg/limit +++ b/tests/ts/dmesg/limit @@ -23,7 +23,7 @@ ts_check_test_command "$TS_HELPER_DMESG" export TZ="GMT" export DMESG_TEST_BOOTIME="1234567890.123456" -$TS_HELPER_DMESG --since @1234567892 --until @1234567991 -F $TS_SELF/input \ +$TS_HELPER_DMESG --since @1234567890.124 --until @1234567991 -F $TS_SELF/input \ >> $TS_OUTPUT 2> $TS_ERRLOG ts_finalize