journal-file: write machine ID when create the file, not when we open it for writing
authorLennart Poettering <lennart@poettering.net>
Thu, 26 Jan 2023 16:12:25 +0000 (17:12 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 21 Feb 2023 09:47:53 +0000 (10:47 +0100)
commit8e64ec04705e029cc891cd1382865ce25b04685c
tree80a47745112c0b07b6279bdac1cc4b51026903e6
parent9204fc642acef5cfc3a411fdec3ce9a5fd9f8d37
journal-file: write machine ID when create the file, not when we open it for writing

This doesn't actually change much, but makes the code less surprising.

Status quo ante:

1. Open a journal file
2. If newly created set header machine ID to zero
3. If existing and open for write check if machine ID in header matches
   local one, if not, refuse.
4. if open for writing, now refresh the machine ID from the local system

Of course, step 4 is pretty much pointless for existing files, as the
check in 3 made sure it is already in order or we'd refuse operating on
it anyway. With this patch this is simplified to:

1. Open a journal file
2. If newly created initialized machine ID to local machine ID
3. If existing, compare machine ID in header with local one, if not
   matching refuse.

Outcome is the same.
src/libsystemd/sd-journal/journal-file.c