]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-journal-dump: dump the headers of journal files
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 30 Jul 2025 09:33:35 +0000 (11:33 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 30 Jul 2025 13:51:00 +0000 (15:51 +0200)
We have journal_file_print_header(), but it's not exposed anywhere in
a way that it is easy to call.

src/libsystemd/meson.build
src/libsystemd/sd-journal/test-journal-dump.c [new file with mode: 0644]

index fa483836fa5edf0ac1f226e25f012923f41e47a8..1cec32523896609e0cff02919664bb531f26f91e 100644 (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,
diff --git a/src/libsystemd/sd-journal/test-journal-dump.c b/src/libsystemd/sd-journal/test-journal-dump.c
new file mode 100644 (file)
index 0000000..bac2fb9
--- /dev/null
@@ -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);