|
8 | 8 | #include "alloc-util.h"
|
9 | 9 | #include "chattr-util.h"
|
10 | 10 | #include "journal-internal.h"
|
| 11 | +#include "logs-show.h" |
11 | 12 | #include "macro.h"
|
12 | 13 | #include "managed-journal-file.h"
|
13 | 14 | #include "path-util.h"
|
@@ -67,6 +68,40 @@ static void test_journal_flush_one(int argc, char *argv[]) {
|
67 | 68 | break;
|
68 | 69 | }
|
69 | 70 |
|
| 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 | + |
70 | 105 | unlink(fn);
|
71 | 106 | assert_se(rmdir(dn) == 0);
|
72 | 107 | }
|
|
0 commit comments