]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/test-journal-flush.c
core: reduce scope of variants
[thirdparty/systemd.git] / src / journal / test-journal-flush.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <fcntl.h>
4 #include <unistd.h>
5
6 #include "sd-journal.h"
7
8 #include "alloc-util.h"
9 #include "chattr-util.h"
10 #include "journal-file.h"
11 #include "journal-internal.h"
12 #include "macro.h"
13 #include "path-util.h"
14 #include "string-util.h"
15
16 int main(int argc, char *argv[]) {
17 _cleanup_free_ char *fn = NULL;
18 char dn[] = "/var/tmp/test-journal-flush.XXXXXX";
19 JournalFile *new_journal = NULL;
20 sd_journal *j = NULL;
21 unsigned n = 0;
22 int r;
23
24 assert_se(mkdtemp(dn));
25 (void) chattr_path(dn, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
26
27 fn = path_join(dn, "test.journal");
28
29 r = journal_file_open(-1, fn, O_CREAT|O_RDWR, 0644, false, 0, false, NULL, NULL, NULL, NULL, &new_journal);
30 assert_se(r >= 0);
31
32 r = sd_journal_open(&j, 0);
33 assert_se(r >= 0);
34
35 sd_journal_set_data_threshold(j, 0);
36
37 SD_JOURNAL_FOREACH(j) {
38 Object *o;
39 JournalFile *f;
40
41 f = j->current_file;
42 assert_se(f && f->current_offset > 0);
43
44 r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o);
45 if (r < 0)
46 log_error_errno(r, "journal_file_move_to_object failed: %m");
47 assert_se(r >= 0);
48
49 r = journal_file_copy_entry(f, new_journal, o, f->current_offset);
50 if (r < 0)
51 log_error_errno(r, "journal_file_copy_entry failed: %m");
52 assert_se(r >= 0);
53
54 if (++n >= 10000)
55 break;
56 }
57
58 sd_journal_close(j);
59
60 (void) journal_file_close(new_journal);
61
62 unlink(fn);
63 assert_se(rmdir(dn) == 0);
64
65 return 0;
66 }