Debian Codegraph @

src/libsystemd/sd-journal/test-journal-dump.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "errno-util.h"
4 #include "journal-file.h"
5 #include "log.h"
6 #include "main-func.h"
7 #include "pager.h"
8 #include "strv.h"
9
10 static int run(int argc, char *argv[]) {
11 int r = 0;
12 unsigned n = 0;
13
14 _cleanup_(mmap_cache_unrefp) MMapCache *m = mmap_cache_new();
15 assert_se(m);
16
17 pager_open(/* flags= */ 0);
18
19 STRV_FOREACH(s, strv_skip(argv, 1)) {
20 JournalFile *f = NULL;
21
22 int k = journal_file_open(
23 /* fd= */ -EBADF,
24 *s,
25 O_RDONLY,
26 /* file_flags= */ 0,
27 0666,
28 /* compress_threshold_bytes= */ UINT64_MAX,
29 /* metrics= */ NULL,
30 m,
31 /* template= */ NULL,
32 &f);
33 if (k < 0)
34 RET_GATHER(r, log_error_errno(k, "Failed to open %s, continuing: %m", *s));
35
36 if (n++ > 0)
37 puts("");
38
39 journal_file_print_header(f);
40 journal_file_close(f);
41 }
42
43 return r;
44 }
45
46 DEFINE_MAIN_FUNCTION(run);