]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logs-show: be more careful when initializing get_dual_timestamp() return parameters 24968/head
authorLennart Poettering <lennart@poettering.net>
Tue, 11 Oct 2022 14:39:51 +0000 (16:39 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 11 Oct 2022 14:40:53 +0000 (16:40 +0200)
make sure we always have something to return in all return parameters,
including in the boot id return parameter, in all code paths.

Follow-up for: #24965

src/shared/logs-show.c

index 562fe0e78d83cb742a4e6b1a59939e38c15bb1fe..d6294a543c806fb65760f6c9cf850144465ba58b 100644 (file)
@@ -1267,6 +1267,7 @@ static int get_dual_timestamp(sd_journal *j, dual_timestamp *ret_ts, sd_id128_t
                 PARSE_FIELD_VEC_ENTRY("_SOURCE_MONOTONIC_TIMESTAMP=", &monotonic, &monotonic_len),
         };
         int r;
+        bool realtime_good = false, monotonic_good = false, boot_id_good = false;
 
         assert(j);
         assert(ret_ts);
@@ -1284,21 +1285,24 @@ static int get_dual_timestamp(sd_journal *j, dual_timestamp *ret_ts, sd_id128_t
                 return r;
 
         if (realtime)
-                r = safe_atou64(realtime, &ret_ts->realtime);
-        if (!realtime || r < 0 || !VALID_REALTIME(ret_ts->realtime))
-                r = sd_journal_get_realtime_usec(j, &ret_ts->realtime);
-        if (r < 0)
+                realtime_good = safe_atou64(realtime, &ret_ts->realtime) >= 0;
+        if (!realtime_good || !VALID_REALTIME(ret_ts->realtime))
+                realtime_good = sd_journal_get_realtime_usec(j, &ret_ts->realtime) >= 0;
+        if (!realtime_good)
                 ret_ts->realtime = USEC_INFINITY;
 
         if (monotonic)
-                r = safe_atou64(monotonic, &ret_ts->monotonic);
-        r = sd_journal_get_monotonic_usec(
-                        j,
-                        !monotonic || r < 0 || !VALID_MONOTONIC(ret_ts->monotonic) ? &ret_ts->monotonic : NULL,
-                        ret_boot_id);
-        if (r < 0)
+                monotonic_good = safe_atou64(monotonic, &ret_ts->monotonic) >= 0;
+        if (!monotonic_good || !VALID_MONOTONIC(ret_ts->monotonic))
+                monotonic_good = boot_id_good = sd_journal_get_monotonic_usec(j, &ret_ts->monotonic, ret_boot_id) >= 0;
+        if (!monotonic_good)
                 ret_ts->monotonic = USEC_INFINITY;
 
+        if (!boot_id_good)
+                boot_id_good = sd_journal_get_monotonic_usec(j, NULL, ret_boot_id) >= 0;
+        if (!boot_id_good)
+                *ret_boot_id = SD_ID128_NULL;
+
         /* Restart all data before */
         sd_journal_restart_data(j);
         sd_journal_restart_unique(j);