]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/journal/test-journal-flush.c
test-journal: move tests to /var/tmp/ and set FS_NOCOW_FL
[thirdparty/systemd.git] / src / journal / test-journal-flush.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
d0767ffd
LP
2
3#include <fcntl.h>
ca78ad1d 4#include <unistd.h>
d0767ffd
LP
5
6#include "sd-journal.h"
07630cea 7
b5efdb8a 8#include "alloc-util.h"
949082ac 9#include "chattr-util.h"
d0767ffd
LP
10#include "journal-file.h"
11#include "journal-internal.h"
07630cea
LP
12#include "macro.h"
13#include "string-util.h"
d0767ffd
LP
14
15int main(int argc, char *argv[]) {
3e348b8a
RC
16 _cleanup_free_ char *fn = NULL;
17 char dn[] = "/var/tmp/test-journal-flush.XXXXXX";
d0767ffd
LP
18 JournalFile *new_journal = NULL;
19 sd_journal *j = NULL;
20 unsigned n = 0;
21 int r;
22
dfd9cf7f 23 assert_se(mkdtemp(dn));
949082ac
LP
24 (void) chattr_path(dn, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
25
dfd9cf7f 26 fn = strappend(dn, "/test.journal");
d0767ffd 27
57850536 28 r = journal_file_open(-1, fn, O_CREAT|O_RDWR, 0644, false, 0, false, NULL, NULL, NULL, NULL, &new_journal);
d0767ffd
LP
29 assert_se(r >= 0);
30
d0767ffd
LP
31 r = sd_journal_open(&j, 0);
32 assert_se(r >= 0);
33
34 sd_journal_set_data_threshold(j, 0);
35
36 SD_JOURNAL_FOREACH(j) {
37 Object *o;
38 JournalFile *f;
39
40 f = j->current_file;
0c0cdb06 41 assert_se(f && f->current_offset > 0);
d0767ffd
LP
42
43 r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o);
0c0cdb06 44 assert_se(r >= 0);
d0767ffd 45
5a271b08 46 r = journal_file_copy_entry(f, new_journal, o, f->current_offset);
0c0cdb06 47 assert_se(r >= 0);
d0767ffd
LP
48
49 n++;
50 if (n > 10000)
51 break;
52 }
53
54 sd_journal_close(j);
55
69a3a6fd 56 (void) journal_file_close(new_journal);
d0767ffd 57
2678031a 58 unlink(fn);
dfd9cf7f
ZJS
59 assert_se(rmdir(dn) == 0);
60
d0767ffd
LP
61 return 0;
62}