From: Lennart Poettering Date: Wed, 8 Feb 2023 10:05:46 +0000 (+0100) Subject: journal: modernize sd_journal_get_realtime_usec() a bit X-Git-Tag: v253-rc3~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=834f759c4942aaea68ab4cfc72d311fa43f8dd9f;p=thirdparty%2Fsystemd.git 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. --- 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; }