]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/test-journal-flush.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 #include "sd-journal.h"
8 #include "alloc-util.h"
9 #include "chattr-util.h"
10 #include "journal-file.h"
11 #include "journal-internal.h"
13 #include "path-util.h"
14 #include "string-util.h"
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
;
24 assert_se(mkdtemp(dn
));
25 (void) chattr_path(dn
, FS_NOCOW_FL
, FS_NOCOW_FL
, NULL
);
27 fn
= path_join(dn
, "test.journal");
29 r
= journal_file_open(-1, fn
, O_CREAT
|O_RDWR
, 0644, false, 0, false, NULL
, NULL
, NULL
, NULL
, &new_journal
);
32 r
= sd_journal_open(&j
, 0);
35 sd_journal_set_data_threshold(j
, 0);
37 SD_JOURNAL_FOREACH(j
) {
42 assert_se(f
&& f
->current_offset
> 0);
44 r
= journal_file_move_to_object(f
, OBJECT_ENTRY
, f
->current_offset
, &o
);
46 log_error_errno(r
, "journal_file_move_to_object failed: %m");
49 r
= journal_file_copy_entry(f
, new_journal
, o
, f
->current_offset
);
51 log_error_errno(r
, "journal_file_copy_entry failed: %m");
60 (void) journal_file_close(new_journal
);
63 assert_se(rmdir(dn
) == 0);