From df04b9ed86a8b45c25cfff0fd800adb66407309a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 12 Oct 2022 16:19:27 +0900 Subject: [PATCH] sd-journal: add comments that journal_file_move_to() may break previous read data We have already made similar mistakes several times, e.g. b8478c14c7367c3ec5d47d2680a3390b0dedecb1, and b596d06c385e104fc330288b791a56661f0c2d17. Let's document the function invalidates previously read objects. --- src/libsystemd/sd-journal/journal-file.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index 54bad925b2a..02e9b9a6742 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -643,6 +643,10 @@ static int journal_file_move_to( assert(f); assert(ret); + /* This function may clear, overwrite, or alter previously cached entries. After this function has + * been called, all objects except for one obtained by this function are invalidated and must be + * re-read before use. */ + if (size <= 0) return -EINVAL; @@ -878,6 +882,10 @@ int journal_file_move_to_object(JournalFile *f, ObjectType type, uint64_t offset assert(f); + /* Even if this function fails, it may clear, overwrite, or alter previously cached entries. After + * this function has been called, all objects except for one obtained by this function are + * invalidated and must be re-read before use.. */ + /* Objects may only be located at multiple of 64 bit */ if (!VALID64(offset)) return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG), -- 2.47.3