test-journal-dump: dump the headers of journal files

We have journal_file_print_header(), but it's not exposed anywhere in
a way that it is easy to call.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2025-07-30 15:51:00 +02:00
parent e7feab79bc
commit 58ecb72bcf
2 changed files with 50 additions and 0 deletions
+4
View File
@@ -275,6 +275,10 @@ libsystemd_tests += [
'sources' : files('sd-journal/test-journal-append.c'),
'type' : 'manual',
},
{
'sources' : files('sd-journal/test-journal-dump.c'),
'type' : 'manual',
},
{
'sources' : files('sd-journal/test-journal-verify.c'),
'timeout' : 90,
@@ -0,0 +1,46 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "errno-util.h"
#include "journal-file.h"
#include "log.h"
#include "main-func.h"
#include "pager.h"
#include "strv.h"
static int run(int argc, char *argv[]) {
int r = 0;
unsigned n = 0;
_cleanup_(mmap_cache_unrefp) MMapCache *m = mmap_cache_new();
assert_se(m);
pager_open(/* flags= */ 0);
STRV_FOREACH(s, strv_skip(argv, 1)) {
JournalFile *f = NULL;
int k = journal_file_open(
/* fd= */ -EBADF,
*s,
O_RDONLY,
/* file_flags= */ 0,
0666,
/* compress_threshold_bytes= */ UINT64_MAX,
/* metrics= */ NULL,
m,
/* template= */ NULL,
&f);
if (k < 0)
RET_GATHER(r, log_error_errno(k, "Failed to open %s, continuing: %m", *s));
if (n++ > 0)
puts("");
journal_file_print_header(f);
journal_file_close(f);
}
return r;
}
DEFINE_MAIN_FUNCTION(run);