mirror of
https://github.com/systemd/systemd
synced 2024-09-06 16:56:43 +00:00
Merge pull request #26204 from poettering/journal-header-compoung-init
journal: use compound initialization for journal file "Header" structure
This commit is contained in:
commit
79f7681621
|
@ -195,7 +195,7 @@ enum {
|
|||
#endif
|
||||
|
||||
#define HEADER_SIGNATURE \
|
||||
((const char[]) { 'L', 'P', 'K', 'S', 'H', 'H', 'R', 'H' })
|
||||
((const uint8_t[]) { 'L', 'P', 'K', 'S', 'H', 'H', 'R', 'H' })
|
||||
|
||||
#define struct_Header__contents { \
|
||||
uint8_t signature[8]; /* "LPKSHHRH" */ \
|
||||
|
|
|
@ -335,9 +335,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);
|
||||
|
@ -347,16 +346,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)));
|
||||
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.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);
|
||||
|
||||
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)
|
||||
|
@ -371,7 +371,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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue