Skip to content

Commit 08df53c

Browse files
yuwataorgads
authored andcommitted
test: add reproducer for SIGBUS issue caused by journal truncation
The added code fails without the previous commit. For issue #24320. (cherry picked from commit 3b0ae13)
1 parent c514ba2 commit 08df53c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/journal/test-journal-flush.c

+35
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "alloc-util.h"
99
#include "chattr-util.h"
1010
#include "journal-internal.h"
11+
#include "logs-show.h"
1112
#include "macro.h"
1213
#include "managed-journal-file.h"
1314
#include "path-util.h"
@@ -67,6 +68,40 @@ static void test_journal_flush_one(int argc, char *argv[]) {
6768
break;
6869
}
6970

71+
if (n == 0)
72+
return (void) log_tests_skipped("No journal entry found");
73+
74+
/* Open the new journal before archiving and offlining the file. */
75+
sd_journal_close(j);
76+
assert_se(sd_journal_open_directory(&j, dn, 0) >= 0);
77+
78+
/* Read the online journal. */
79+
assert_se(sd_journal_seek_tail(j) >= 0);
80+
assert_se(sd_journal_step_one(j, 0) > 0);
81+
printf("current_journal: %s (%i)\n", j->current_file->path, j->current_file->fd);
82+
assert_se(show_journal_entry(stdout, j, OUTPUT_EXPORT, 0, 0, NULL, NULL, NULL, &(dual_timestamp) {}, &(sd_id128_t) {}) >= 0);
83+
84+
uint64_t p;
85+
assert_se(journal_file_tail_end_by_mmap(j->current_file, &p) >= 0);
86+
for (uint64_t q = ALIGN64(p + 1); q < (uint64_t) j->current_file->last_stat.st_size; q = ALIGN64(q + 1)) {
87+
Object *o;
88+
89+
r = journal_file_move_to_object(j->current_file, OBJECT_UNUSED, q, &o);
90+
assert_se(IN_SET(r, -EBADMSG, -EADDRNOTAVAIL));
91+
}
92+
93+
/* Archive and offline file. */
94+
assert_se(journal_file_archive(new_journal, NULL) >= 0);
95+
assert_se(journal_file_set_offline(new_journal, /* wait = */ true) >= 0);
96+
97+
/* Read the archived and offline journal. */
98+
for (uint64_t q = ALIGN64(p + 1); q < (uint64_t) j->current_file->last_stat.st_size; q = ALIGN64(q + 1)) {
99+
Object *o;
100+
101+
r = journal_file_move_to_object(j->current_file, OBJECT_UNUSED, q, &o);
102+
assert_se(IN_SET(r, -EBADMSG, -EADDRNOTAVAIL, -EIDRM));
103+
}
104+
70105
unlink(fn);
71106
assert_se(rmdir(dn) == 0);
72107
}

0 commit comments

Comments
 (0)