]>
Commit | Line | Data |
---|---|---|
d0767ffd LP |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2013 Lennart Poettering | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
22 | #include <fcntl.h> | |
23 | ||
24 | #include "sd-journal.h" | |
07630cea | 25 | |
d0767ffd LP |
26 | #include "journal-file.h" |
27 | #include "journal-internal.h" | |
07630cea LP |
28 | #include "macro.h" |
29 | #include "string-util.h" | |
d0767ffd LP |
30 | |
31 | int main(int argc, char *argv[]) { | |
3e348b8a RC |
32 | _cleanup_free_ char *fn = NULL; |
33 | char dn[] = "/var/tmp/test-journal-flush.XXXXXX"; | |
d0767ffd LP |
34 | JournalFile *new_journal = NULL; |
35 | sd_journal *j = NULL; | |
36 | unsigned n = 0; | |
37 | int r; | |
38 | ||
dfd9cf7f ZJS |
39 | assert_se(mkdtemp(dn)); |
40 | fn = strappend(dn, "/test.journal"); | |
d0767ffd LP |
41 | |
42 | r = journal_file_open(fn, O_CREAT|O_RDWR, 0644, false, false, NULL, NULL, NULL, &new_journal); | |
43 | assert_se(r >= 0); | |
44 | ||
d0767ffd LP |
45 | r = sd_journal_open(&j, 0); |
46 | assert_se(r >= 0); | |
47 | ||
48 | sd_journal_set_data_threshold(j, 0); | |
49 | ||
50 | SD_JOURNAL_FOREACH(j) { | |
51 | Object *o; | |
52 | JournalFile *f; | |
53 | ||
54 | f = j->current_file; | |
0c0cdb06 | 55 | assert_se(f && f->current_offset > 0); |
d0767ffd LP |
56 | |
57 | r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o); | |
0c0cdb06 | 58 | assert_se(r >= 0); |
d0767ffd LP |
59 | |
60 | r = journal_file_copy_entry(f, new_journal, o, f->current_offset, NULL, NULL, NULL); | |
0c0cdb06 | 61 | assert_se(r >= 0); |
d0767ffd LP |
62 | |
63 | n++; | |
64 | if (n > 10000) | |
65 | break; | |
66 | } | |
67 | ||
68 | sd_journal_close(j); | |
69 | ||
70 | journal_file_close(new_journal); | |
71 | ||
2678031a | 72 | unlink(fn); |
dfd9cf7f ZJS |
73 | assert_se(rmdir(dn) == 0); |
74 | ||
d0767ffd LP |
75 | return 0; |
76 | } |