Skip to content

Commit

Permalink
journal-file-util: use COPY_VERIFY_LINKED
Browse files Browse the repository at this point in the history
As the main thread may call journal_directory_vacuum() ->
unlinkat_deallocate() while another thread is copying the file.

Fixes systemd#24150 and systemd#31222.
  • Loading branch information
yuwata committed Feb 15, 2024
1 parent d324748 commit 68fccfe
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/shared/journal-file-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,15 @@ static void journal_file_set_offline_internal(JournalFile *f) {

log_debug_errno(r, "Failed to re-enable copy-on-write for %s: %m, rewriting file", f->path);

/* Here, setting COPY_VERIFY_LINKED flag is crucial. Otherwise, a broken
* journal file may be created, if journal_directory_vacuum() ->
* unlinkat_deallocate() is called in the main thread while this thread is
* copying the file. See issue #24150 and #31222. */
r = copy_file_atomic_at_full(
f->fd, NULL, AT_FDCWD, f->path, f->mode,
0,
FS_NOCOW_FL,
COPY_REPLACE | COPY_FSYNC | COPY_HOLES | COPY_ALL_XATTRS,
COPY_REPLACE | COPY_FSYNC | COPY_HOLES | COPY_ALL_XATTRS | COPY_VERIFY_LINKED,
NULL, NULL);
if (r < 0) {
log_debug_errno(r, "Failed to rewrite %s: %m", f->path);
Expand Down

0 comments on commit 68fccfe

Please sign in to comment.