summaryrefslogtreecommitdiff
path: root/src/journal/test-journal-verify.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2021-12-07 14:18:14 -0800
committerVito Caputo <vcaputo@pengaru.com>2021-12-07 14:39:20 -0800
commit74fb5be62d163ce234cc37fd0166bc587cc23e07 (patch)
treeb385bcc10d9f84d0348cec22fdfe2b330253cbc2 /src/journal/test-journal-verify.c
parent333d0672625b0b466f9d1d7b46e452105ec13a2b (diff)
downloadsystemd-74fb5be62d163ce234cc37fd0166bc587cc23e07.tar.gz
journal-file: require MMapCache* for journal_file_open()
Previously the MMapCache* was optionally NULL, which open would handle by creating a new MMapCache* for the occasion. This produced some slightly circuitous refcount-handling code in the function, as well as arguably creating opportunities for weirdness where an MMapCache* was intended to be supplied but happened to be NULL, which this magic would then paper over. In any case, this was basically only being utilized by tests, apparently just to avoid having to create an MMapCache. So update the relevant tests to supply an MMapCache and make journal_file_open() treat a NULL MMapCache* as fatal w/assert.
Diffstat (limited to 'src/journal/test-journal-verify.c')
-rw-r--r--src/journal/test-journal-verify.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/journal/test-journal-verify.c b/src/journal/test-journal-verify.c
index cf9692b3d2..6abfaeb0df 100644
--- a/src/journal/test-journal-verify.c
+++ b/src/journal/test-journal-verify.c
@@ -10,6 +10,7 @@
#include "journald-file.h"
#include "journal-verify.h"
#include "log.h"
+#include "mmap-cache.h"
#include "rm-rf.h"
#include "terminal-util.h"
#include "tests.h"
@@ -38,10 +39,14 @@ static void bit_toggle(const char *fn, uint64_t p) {
}
static int raw_verify(const char *fn, const char *verification_key) {
+ _cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
JournalFile *f;
int r;
- r = journal_file_open(-1, fn, O_RDONLY, 0666, true, UINT64_MAX, !!verification_key, NULL, NULL, NULL, &f);
+ m = mmap_cache_new();
+ assert_se(m != NULL);
+
+ r = journal_file_open(-1, fn, O_RDONLY, 0666, true, UINT64_MAX, !!verification_key, NULL, m, NULL, &f);
if (r < 0)
return r;
@@ -52,6 +57,7 @@ static int raw_verify(const char *fn, const char *verification_key) {
}
int main(int argc, char *argv[]) {
+ _cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
char t[] = "/var/tmp/journal-XXXXXX";
unsigned n;
JournalFile *f;
@@ -61,6 +67,9 @@ int main(int argc, char *argv[]) {
struct stat st;
uint64_t p;
+ m = mmap_cache_new();
+ assert_se(m != NULL);
+
/* journald_file_open requires a valid machine id */
if (access("/etc/machine-id", F_OK) != 0)
return log_tests_skipped("/etc/machine-id not found");
@@ -73,7 +82,7 @@ int main(int argc, char *argv[]) {
log_info("Generating...");
- assert_se(journald_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, !!verification_key, NULL, NULL, NULL, NULL, &df) == 0);
+ assert_se(journald_file_open(-1, "test.journal", O_RDWR|O_CREAT, 0666, true, UINT64_MAX, !!verification_key, NULL, m, NULL, NULL, &df) == 0);
for (n = 0; n < N_ENTRIES; n++) {
struct iovec iovec;
@@ -95,7 +104,7 @@ int main(int argc, char *argv[]) {
log_info("Verifying...");
- assert_se(journal_file_open(-1, "test.journal", O_RDONLY, 0666, true, UINT64_MAX, !!verification_key, NULL, NULL, NULL, &f) == 0);
+ assert_se(journal_file_open(-1, "test.journal", O_RDONLY, 0666, true, UINT64_MAX, !!verification_key, NULL, m, NULL, &f) == 0);
/* journal_file_print_header(f); */
journal_file_dump(f);