From 834f759c4942aaea68ab4cfc72d311fa43f8dd9f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 8 Feb 2023 11:05:46 +0100 Subject: [PATCH] journal: modernize sd_journal_get_realtime_usec() a bit This does what 404803e6caad2de2d8e74caab0b79ec3f030f801 did for the monotonic timestamp getter, but for the realtime timestamp. It also also makes the return value optional, exactly as for the monotonic timestamp logic. --- src/libsystemd/sd-journal/sd-journal.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c index 659e1e4e348..9947947ef2b 100644 --- a/src/libsystemd/sd-journal/sd-journal.c +++ b/src/libsystemd/sd-journal/sd-journal.c @@ -2164,18 +2164,16 @@ _public_ void sd_journal_close(sd_journal *j) { } _public_ int sd_journal_get_realtime_usec(sd_journal *j, uint64_t *ret) { - Object *o; JournalFile *f; + Object *o; int r; assert_return(j, -EINVAL); assert_return(!journal_pid_changed(j), -ECHILD); - assert_return(ret, -EINVAL); f = j->current_file; if (!f) return -EADDRNOTAVAIL; - if (f->current_offset <= 0) return -EADDRNOTAVAIL; @@ -2183,7 +2181,13 @@ _public_ int sd_journal_get_realtime_usec(sd_journal *j, uint64_t *ret) { if (r < 0) return r; - *ret = le64toh(o->entry.realtime); + uint64_t t = le64toh(o->entry.realtime); + if (!VALID_REALTIME(t)) + return -EBADMSG; + + if (ret) + *ret = t; + return 0; } -- 2.47.3