shared/logs-show: avoid printing "(null)" when timestamp is not specified
$ perl -e 'print("MESSAGE\n", pack("q<", 1), "A\n\nMESSAGE=test2\n")' > message.bin
$ systemd-journal-remote -o /tmp/out.journal message.bin
$ journalctl -o export --file /tmp/out.journal
__CURSOR=s=b16c464c2db44384b29e75a564d8388e;i=1;b=6b0be47627bd4932913dc126012c21c0;m=0;t=0;x=b04263a253e357a
__REALTIME_TIMESTAMP=0
__MONOTONIC_TIMESTAMP=0
_BOOT_ID=6b0be47627bd4932913dc126012c21c0
MESSAGE=A
$ journalctl -o verbose --file /tmp/out.journal
(null) [s=b16c464c2db44384b29e75a564d8388e;i=1;b=6b0be47627bd4932913dc126012c21c0;m=0;t=0;x=b04263a253e357a]
MESSAGE=A
This is changed to
$ build/journalctl -o verbose --file /tmp/out.journal
(no timestamp) [s=b16c464c2db44384b29e75a564d8388e;i=1;b=6b0be47627bd4932913dc126012c21c0;m=0;t=0;x=b04263a253e357a]
MESSAGE=A
We should deal gracefully with unexpected input.
This commit is contained in:
@@ -485,6 +485,7 @@ static int output_verbose(
|
||||
_cleanup_free_ char *cursor = NULL;
|
||||
uint64_t realtime = 0;
|
||||
char ts[FORMAT_TIMESTAMP_MAX + 7];
|
||||
const char *timestamp;
|
||||
int r;
|
||||
|
||||
assert(f);
|
||||
@@ -520,10 +521,10 @@ static int output_verbose(
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get cursor: %m");
|
||||
|
||||
timestamp = flags & OUTPUT_UTC ? format_timestamp_us_utc(ts, sizeof ts, realtime)
|
||||
: format_timestamp_us(ts, sizeof ts, realtime);
|
||||
fprintf(f, "%s [%s]\n",
|
||||
flags & OUTPUT_UTC ?
|
||||
format_timestamp_us_utc(ts, sizeof(ts), realtime) :
|
||||
format_timestamp_us(ts, sizeof(ts), realtime),
|
||||
timestamp ?: "(no timestamp)",
|
||||
cursor);
|
||||
|
||||
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
|
||||
|
||||
Reference in New Issue
Block a user