Skip to content

Commit 32f9e12

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 db14a20 commit 32f9e12

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/journal/test-journal-flush.c

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

72107
TEST(journal_flush) {

0 commit comments

Comments
 (0)