2023-11-07 11:29:40 +00:00
|
|
|
From b418b2d17e258f10211b529f9beb8b090283307f Mon Sep 17 00:00:00 2001
|
2023-06-23 12:24:58 +00:00
|
|
|
From: Lennart Poettering <lennart@poettering.net>
|
|
|
|
Date: Wed, 25 Jan 2023 18:48:31 +0100
|
|
|
|
Subject: [PATCH] journal: use compound initialization for journal file Header
|
|
|
|
structure
|
|
|
|
|
|
|
|
(cherry picked from commit c3dd0dcb888fd8da7ce4e5299caf45e90ddcd41b)
|
|
|
|
|
2023-11-07 11:29:40 +00:00
|
|
|
Related: #2183546
|
2023-06-23 12:24:58 +00:00
|
|
|
---
|
|
|
|
src/libsystemd/sd-journal/journal-file.c | 23 +++++++++++------------
|
|
|
|
1 file changed, 11 insertions(+), 12 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c
|
|
|
|
index c489436a1e..cf86bab2dc 100644
|
|
|
|
--- a/src/libsystemd/sd-journal/journal-file.c
|
|
|
|
+++ b/src/libsystemd/sd-journal/journal-file.c
|
|
|
|
@@ -320,9 +320,8 @@ static bool compact_mode_requested(void) {
|
|
|
|
}
|
|
|
|
|
|
|
|
static int journal_file_init_header(JournalFile *f, JournalFileFlags file_flags, JournalFile *template) {
|
|
|
|
- Header h = {};
|
|
|
|
- ssize_t k;
|
|
|
|
bool seal = false;
|
|
|
|
+ ssize_t k;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(f);
|
|
|
|
@@ -332,16 +331,17 @@ static int journal_file_init_header(JournalFile *f, JournalFileFlags file_flags,
|
|
|
|
seal = FLAGS_SET(file_flags, JOURNAL_SEAL) && journal_file_fss_load(f) >= 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
- memcpy(h.signature, HEADER_SIGNATURE, 8);
|
|
|
|
- h.header_size = htole64(ALIGN64(sizeof(h)));
|
|
|
|
-
|
|
|
|
- h.incompatible_flags |= htole32(
|
|
|
|
- FLAGS_SET(file_flags, JOURNAL_COMPRESS) *
|
|
|
|
- COMPRESSION_TO_HEADER_INCOMPATIBLE_FLAG(DEFAULT_COMPRESSION) |
|
|
|
|
- keyed_hash_requested() * HEADER_INCOMPATIBLE_KEYED_HASH |
|
|
|
|
- compact_mode_requested() * HEADER_INCOMPATIBLE_COMPACT);
|
|
|
|
+ Header h = {
|
|
|
|
+ .header_size = htole64(ALIGN64(sizeof(h))),
|
|
|
|
+ .incompatible_flags = htole32(
|
|
|
|
+ FLAGS_SET(file_flags, JOURNAL_COMPRESS) * COMPRESSION_TO_HEADER_INCOMPATIBLE_FLAG(DEFAULT_COMPRESSION) |
|
|
|
|
+ keyed_hash_requested() * HEADER_INCOMPATIBLE_KEYED_HASH |
|
|
|
|
+ compact_mode_requested() * HEADER_INCOMPATIBLE_COMPACT),
|
|
|
|
+ .compatible_flags = htole32(seal * HEADER_COMPATIBLE_SEALED),
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- h.compatible_flags = htole32(seal * HEADER_COMPATIBLE_SEALED);
|
|
|
|
+ assert_cc(sizeof(h.signature) == sizeof(HEADER_SIGNATURE));
|
|
|
|
+ memcpy(h.signature, HEADER_SIGNATURE, sizeof(HEADER_SIGNATURE));
|
|
|
|
|
|
|
|
r = sd_id128_randomize(&h.file_id);
|
|
|
|
if (r < 0)
|
|
|
|
@@ -356,7 +356,6 @@ static int journal_file_init_header(JournalFile *f, JournalFileFlags file_flags,
|
|
|
|
k = pwrite(f->fd, &h, sizeof(h), 0);
|
|
|
|
if (k < 0)
|
|
|
|
return -errno;
|
|
|
|
-
|
|
|
|
if (k != sizeof(h))
|
|
|
|
return -EIO;
|
|
|
|
|