]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: modernize sd_journal_get_realtime_usec() a bit
authorLennart Poettering <lennart@poettering.net>
Wed, 8 Feb 2023 10:05:46 +0000 (11:05 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 8 Feb 2023 17:33:23 +0000 (17:33 +0000)
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

index 659e1e4e348af5fd10f837e878bde62a017f6fc4..9947947ef2b8aa3a9bfc7018fa73b10ceb4cc503 100644 (file)
@@ -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;
 }