]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
d0767ffd LP |
2 | |
3 | #include <fcntl.h> | |
4 | ||
5 | #include "sd-journal.h" | |
07630cea | 6 | |
b5efdb8a | 7 | #include "alloc-util.h" |
d0767ffd LP |
8 | #include "journal-file.h" |
9 | #include "journal-internal.h" | |
07630cea LP |
10 | #include "macro.h" |
11 | #include "string-util.h" | |
d0767ffd LP |
12 | |
13 | int main(int argc, char *argv[]) { | |
3e348b8a RC |
14 | _cleanup_free_ char *fn = NULL; |
15 | char dn[] = "/var/tmp/test-journal-flush.XXXXXX"; | |
d0767ffd LP |
16 | JournalFile *new_journal = NULL; |
17 | sd_journal *j = NULL; | |
18 | unsigned n = 0; | |
19 | int r; | |
20 | ||
dfd9cf7f ZJS |
21 | assert_se(mkdtemp(dn)); |
22 | fn = strappend(dn, "/test.journal"); | |
d0767ffd | 23 | |
57850536 | 24 | r = journal_file_open(-1, fn, O_CREAT|O_RDWR, 0644, false, 0, false, NULL, NULL, NULL, NULL, &new_journal); |
d0767ffd LP |
25 | assert_se(r >= 0); |
26 | ||
d0767ffd LP |
27 | r = sd_journal_open(&j, 0); |
28 | assert_se(r >= 0); | |
29 | ||
30 | sd_journal_set_data_threshold(j, 0); | |
31 | ||
32 | SD_JOURNAL_FOREACH(j) { | |
33 | Object *o; | |
34 | JournalFile *f; | |
35 | ||
36 | f = j->current_file; | |
0c0cdb06 | 37 | assert_se(f && f->current_offset > 0); |
d0767ffd LP |
38 | |
39 | r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o); | |
0c0cdb06 | 40 | assert_se(r >= 0); |
d0767ffd | 41 | |
5a271b08 | 42 | r = journal_file_copy_entry(f, new_journal, o, f->current_offset); |
0c0cdb06 | 43 | assert_se(r >= 0); |
d0767ffd LP |
44 | |
45 | n++; | |
46 | if (n > 10000) | |
47 | break; | |
48 | } | |
49 | ||
50 | sd_journal_close(j); | |
51 | ||
69a3a6fd | 52 | (void) journal_file_close(new_journal); |
d0767ffd | 53 | |
2678031a | 54 | unlink(fn); |
dfd9cf7f ZJS |
55 | assert_se(rmdir(dn) == 0); |
56 | ||
d0767ffd LP |
57 | return 0; |
58 | } |