]>
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" | |
25 | #include "journal-file.h" | |
26 | #include "journal-internal.h" | |
27 | ||
28 | int main(int argc, char *argv[]) { | |
29 | ||
30 | char fn[sizeof("/var/tmp/test-journal-flush-")-1 + DECIMAL_STR_MAX(pid_t) + sizeof(".journal")]; | |
31 | JournalFile *new_journal = NULL; | |
32 | sd_journal *j = NULL; | |
33 | unsigned n = 0; | |
34 | int r; | |
35 | ||
36 | sprintf(fn, "/var/tmp/test-journal-flush-%lu.journal", (unsigned long) getpid()); | |
37 | ||
38 | r = journal_file_open(fn, O_CREAT|O_RDWR, 0644, false, false, NULL, NULL, NULL, &new_journal); | |
39 | assert_se(r >= 0); | |
40 | ||
41 | unlink(fn); | |
42 | ||
43 | r = sd_journal_open(&j, 0); | |
44 | assert_se(r >= 0); | |
45 | ||
46 | sd_journal_set_data_threshold(j, 0); | |
47 | ||
48 | SD_JOURNAL_FOREACH(j) { | |
49 | Object *o; | |
50 | JournalFile *f; | |
51 | ||
52 | f = j->current_file; | |
53 | assert(f && f->current_offset > 0); | |
54 | ||
55 | r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o); | |
56 | assert(r >= 0); | |
57 | ||
58 | r = journal_file_copy_entry(f, new_journal, o, f->current_offset, NULL, NULL, NULL); | |
59 | assert(r >= 0); | |
60 | ||
61 | n++; | |
62 | if (n > 10000) | |
63 | break; | |
64 | } | |
65 | ||
66 | sd_journal_close(j); | |
67 | ||
68 | journal_file_close(new_journal); | |
69 | ||
70 | return 0; | |
71 | } |