summaryrefslogtreecommitdiff
path: root/src/shared/logs-show.c
diff options
context:
space:
mode:
authormsizanoen1 <msizanoen@qtmlabs.xyz>2022-10-12 13:40:05 +0700
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-10-14 18:05:04 +0200
commit417cbcd6be49c2792fb1ed70fefb41cb7ac3c3bf (patch)
tree7b8ea533de26870d0bdc1dcc040ddcbccebd9b8a /src/shared/logs-show.c
parent2ce39d78b8a6c01a0750f648a615606cb186ba43 (diff)
downloadsystemd-417cbcd6be49c2792fb1ed70fefb41cb7ac3c3bf.tar.gz
shared/logs-show: do not overwrite journal time in export format with source timestamps
Using _SOURCE_{MONOTONIC,REALTIME}_TIMESTAMP in place of the results of sd_journal_get_{monotonic,realtime}_usecs in export formats might cause internal inconsistency of realtime timestamp values within a journal export, violating the export file format and causing systemd-journal-remote to mass-generate journal files. Fix this by using the real journal timestamps for __{REALTIME,MONOTONIC}_TIMESTAMP.
Diffstat (limited to 'src/shared/logs-show.c')
-rw-r--r--src/shared/logs-show.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index d6294a543c..2b180a8c0f 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -774,6 +774,8 @@ static int output_export(
_cleanup_free_ char *cursor = NULL;
const void *data;
size_t length;
+ usec_t monotonic, realtime;
+ sd_id128_t journal_boot_id;
int r;
assert(j);
@@ -784,25 +786,27 @@ static int output_export(
sd_journal_set_data_threshold(j, 0);
- if (!VALID_REALTIME(ts->realtime))
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No valid realtime timestamp available");
-
- if (!VALID_MONOTONIC(ts->monotonic))
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No valid monotonic timestamp available");
-
r = sd_journal_get_cursor(j, &cursor);
if (r < 0)
return log_error_errno(r, "Failed to get cursor: %m");
+ r = sd_journal_get_realtime_usec(j, &realtime);
+ if (r < 0)
+ return log_error_errno(r, "Failed to get realtime timestamp: %m");
+
+ r = sd_journal_get_monotonic_usec(j, &monotonic, &journal_boot_id);
+ if (r < 0)
+ return log_error_errno(r, "Failed to get monotonic timestamp: %m");
+
fprintf(f,
"__CURSOR=%s\n"
"__REALTIME_TIMESTAMP="USEC_FMT"\n"
"__MONOTONIC_TIMESTAMP="USEC_FMT"\n"
"_BOOT_ID=%s\n",
cursor,
- ts->realtime,
- ts->monotonic,
- SD_ID128_TO_STRING(*boot_id));
+ realtime,
+ monotonic,
+ SD_ID128_TO_STRING(journal_boot_id));
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
size_t fieldlen;
@@ -1017,6 +1021,8 @@ static int output_json(
struct json_data *d;
Hashmap *h = NULL;
size_t n = 0;
+ usec_t realtime, monotonic;
+ sd_id128_t journal_boot_id;
int r;
assert(j);
@@ -1027,16 +1033,18 @@ static int output_json(
(void) sd_journal_set_data_threshold(j, flags & OUTPUT_SHOW_ALL ? 0 : JSON_THRESHOLD);
- if (!VALID_REALTIME(ts->realtime))
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No valid realtime timestamp available");
-
- if (!VALID_MONOTONIC(ts->monotonic))
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No valid monotonic timestamp available");
-
r = sd_journal_get_cursor(j, &cursor);
if (r < 0)
return log_error_errno(r, "Failed to get cursor: %m");
+ r = sd_journal_get_realtime_usec(j, &realtime);
+ if (r < 0)
+ return log_error_errno(r, "Failed to get realtime timestamp: %m");
+
+ r = sd_journal_get_monotonic_usec(j, &monotonic, &journal_boot_id);
+ if (r < 0)
+ return log_error_errno(r, "Failed to get monotonic timestamp: %m");
+
h = hashmap_new(&string_hash_ops);
if (!h)
return log_oom();
@@ -1045,17 +1053,17 @@ static int output_json(
if (r < 0)
goto finish;
- xsprintf(usecbuf, USEC_FMT, ts->realtime);
+ xsprintf(usecbuf, USEC_FMT, realtime);
r = update_json_data(h, flags, "__REALTIME_TIMESTAMP", usecbuf, strlen(usecbuf));
if (r < 0)
goto finish;
- xsprintf(usecbuf, USEC_FMT, ts->monotonic);
+ xsprintf(usecbuf, USEC_FMT, monotonic);
r = update_json_data(h, flags, "__MONOTONIC_TIMESTAMP", usecbuf, strlen(usecbuf));
if (r < 0)
goto finish;
- sd_id128_to_string(*boot_id, sid);
+ sd_id128_to_string(journal_boot_id, sid);
r = update_json_data(h, flags, "_BOOT_ID", sid, strlen(sid));
if (r < 0)
goto finish;