From 461955ef4c786755471d1f49e51dd374c62f55ea Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 1 Dec 2021 09:34:13 +0100 Subject: [PATCH] journal: Update the JournalFile path when archiving When we archive a path, we rename the file to indicate this. However, until now, we didn't actually update the path member of the corresponding JournalFile instance. Let's make sure we also update this to avoid misuse of the old path later on. This change also requires we save the previous path in journal_file_rotate() since we need to open a new file at the previous path. --- src/journal/journald-file.c | 5 +++-- src/journal/journald-server.c | 2 +- src/libsystemd/sd-journal/journal-file.c | 9 ++++++++- src/libsystemd/sd-journal/journal-file.h | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/journal/journald-file.c b/src/journal/journald-file.c index 5dba791517..fc46aa1963 100644 --- a/src/journal/journald-file.c +++ b/src/journal/journald-file.c @@ -382,19 +382,20 @@ int journald_file_rotate( bool seal, Set *deferred_closes) { + _cleanup_free_ char *path = NULL; JournaldFile *new_file = NULL; int r; assert(f); assert(*f); - r = journal_file_archive((*f)->file); + r = journal_file_archive((*f)->file, &path); if (r < 0) return r; r = journald_file_open( -1, - (*f)->file->path, + path, (*f)->file->flags, (*f)->file->mode, compress, diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 5e97cd41fd..a13bbeeee9 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -602,7 +602,7 @@ static int vacuum_offline_user_journals(Server *s) { TAKE_FD(fd); /* Donated to journald_file_open() */ - r = journal_file_archive(f->file); + r = journal_file_archive(f->file, NULL); if (r < 0) log_debug_errno(r, "Failed to archive journal file '%s', ignoring: %m", full); diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index 9755bf14b9..bc80a51524 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -3521,7 +3521,7 @@ fail: return r; } -int journal_file_archive(JournalFile *f) { +int journal_file_archive(JournalFile *f, char **ret_previous_path) { _cleanup_free_ char *p = NULL; assert(f); @@ -3552,6 +3552,13 @@ int journal_file_archive(JournalFile *f) { /* Sync the rename to disk */ (void) fsync_directory_of_file(f->fd); + if (ret_previous_path) + *ret_previous_path = f->path; + else + free(f->path); + + f->path = TAKE_PTR(p); + /* Set as archive so offlining commits w/state=STATE_ARCHIVED. Previously we would set old_file->header->state * to STATE_ARCHIVED directly here, but journal_file_set_offline() short-circuits when state != STATE_ONLINE, * which would result in the rotated journal never getting fsync() called before closing. Now we simply queue diff --git a/src/libsystemd/sd-journal/journal-file.h b/src/libsystemd/sd-journal/journal-file.h index 6916cc4ac3..5bcf591337 100644 --- a/src/libsystemd/sd-journal/journal-file.h +++ b/src/libsystemd/sd-journal/journal-file.h @@ -232,7 +232,7 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6 void journal_file_dump(JournalFile *f); void journal_file_print_header(JournalFile *f); -int journal_file_archive(JournalFile *f); +int journal_file_archive(JournalFile *f, char **ret_previous_path); int journal_file_dispose(int dir_fd, const char *fname); -- 2.25.1