Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */ 2 : 3 : #include <fcntl.h> 4 : #include <unistd.h> 5 : 6 : #include "sd-journal.h" 7 : 8 : #include "alloc-util.h" 9 : #include "chattr-util.h" 10 : #include "journal-file.h" 11 : #include "journal-internal.h" 12 : #include "macro.h" 13 : #include "path-util.h" 14 : #include "string-util.h" 15 : 16 1 : int main(int argc, char *argv[]) { 17 2 : _cleanup_free_ char *fn = NULL; 18 1 : char dn[] = "/var/tmp/test-journal-flush.XXXXXX"; 19 1 : JournalFile *new_journal = NULL; 20 1 : sd_journal *j = NULL; 21 1 : unsigned n = 0; 22 : int r; 23 : 24 1 : assert_se(mkdtemp(dn)); 25 1 : (void) chattr_path(dn, FS_NOCOW_FL, FS_NOCOW_FL, NULL); 26 : 27 1 : fn = path_join(dn, "test.journal"); 28 : 29 1 : r = journal_file_open(-1, fn, O_CREAT|O_RDWR, 0644, false, 0, false, NULL, NULL, NULL, NULL, &new_journal); 30 1 : assert_se(r >= 0); 31 : 32 1 : r = sd_journal_open(&j, 0); 33 1 : assert_se(r >= 0); 34 : 35 1 : sd_journal_set_data_threshold(j, 0); 36 : 37 10000 : SD_JOURNAL_FOREACH(j) { 38 : Object *o; 39 : JournalFile *f; 40 : 41 10000 : f = j->current_file; 42 10000 : assert_se(f && f->current_offset > 0); 43 : 44 10000 : r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o); 45 10000 : if (r < 0) 46 0 : log_error_errno(r, "journal_file_move_to_object failed: %m"); 47 10000 : assert_se(r >= 0); 48 : 49 10000 : r = journal_file_copy_entry(f, new_journal, o, f->current_offset); 50 10000 : if (r < 0) 51 0 : log_error_errno(r, "journal_file_copy_entry failed: %m"); 52 10000 : assert_se(r >= 0); 53 : 54 10000 : if (++n >= 10000) 55 1 : break; 56 : } 57 : 58 1 : sd_journal_close(j); 59 : 60 1 : (void) journal_file_close(new_journal); 61 : 62 1 : unlink(fn); 63 1 : assert_se(rmdir(dn) == 0); 64 : 65 1 : return 0; 66 : }