]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd/sd-journal/test-journal-flush.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
6 #include "sd-journal.h"
8 #include "alloc-util.h"
9 #include "chattr-util.h"
10 #include "journal-file-util.h"
11 #include "journal-internal.h"
13 #include "path-util.h"
15 #include "string-util.h"
16 #include "tmpfile-util.h"
18 static void test_journal_flush(int argc
, char *argv
[]) {
19 _cleanup_(mmap_cache_unrefp
) MMapCache
*m
= NULL
;
20 _cleanup_free_
char *fn
= NULL
;
21 _cleanup_(rm_rf_physical_and_freep
) char *dn
= NULL
;
22 JournalFile
*new_journal
= NULL
;
27 assert_se(m
= mmap_cache_new());
28 assert_se(mkdtemp_malloc("/var/tmp/test-journal-flush.XXXXXX", &dn
) >= 0);
29 (void) chattr_path(dn
, FS_NOCOW_FL
, FS_NOCOW_FL
, NULL
);
31 assert_se(fn
= path_join(dn
, "test.journal"));
33 r
= journal_file_open(-1, fn
, O_CREAT
|O_RDWR
, 0, 0644, 0, NULL
, m
, NULL
, &new_journal
);
37 r
= sd_journal_open_files(&j
, (const char **) strv_skip(argv
, 1), 0);
39 r
= sd_journal_open(&j
, 0);
42 sd_journal_set_data_threshold(j
, 0);
44 SD_JOURNAL_FOREACH(j
) {
49 assert_se(f
&& f
->current_offset
> 0);
51 r
= journal_file_move_to_object(f
, OBJECT_ENTRY
, f
->current_offset
, &o
);
53 log_error_errno(r
, "journal_file_move_to_object failed: %m");
56 r
= journal_file_copy_entry(f
, new_journal
, o
, f
->current_offset
, NULL
, NULL
);
58 log_warning_errno(r
, "journal_file_copy_entry failed: %m");
60 IN_SET(r
, -EBADMSG
, /* corrupted file */
61 -EPROTONOSUPPORT
, /* unsupported compression */
62 -EIO
, /* file rotated */
63 -EREMCHG
)); /* clock rollback */
71 (void) journal_file_offline_close(new_journal
);
74 int main(int argc
, char *argv
[]) {
75 assert_se(setenv("SYSTEMD_JOURNAL_COMPACT", "0", 1) >= 0);
76 test_journal_flush(argc
, argv
);
78 assert_se(setenv("SYSTEMD_JOURNAL_COMPACT", "1", 1) >= 0);
79 test_journal_flush(argc
, argv
);