diff options
author | Michal Sekletár <msekleta@redhat.com> | 2020-02-04 14:23:14 +0100 |
---|---|---|
committer | The Plumber <50238977+systemd-rhel-bot@users.noreply.github.com> | 2020-05-04 16:20:31 +0200 |
commit | 0d33f461f8b824ab94239c1c1495c2cb7c9de54f (patch) | |
tree | aea7629a4e8d8677dc8ee60d8e96825e5d8dc828 /src/journal/sd-journal.c | |
parent | 8a9a0b62a58e1481b6a0f2e54b323b4eefadc4fd (diff) | |
download | systemd-0d33f461f8b824ab94239c1c1495c2cb7c9de54f.tar.gz |
sd-journal: close journal files that were deleted by journald before we've setup inotify watch
Fixes #14695
(cherry picked from commit 28ca867abdb20d0e4ac1901e2ed669cdb41ea3f6)
Related: #1826216
Diffstat (limited to 'src/journal/sd-journal.c')
-rw-r--r-- | src/journal/sd-journal.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 323300baec..c06255e273 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -2584,6 +2584,8 @@ _public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) { assert_return(!journal_pid_changed(j), -ECHILD); if (j->inotify_fd < 0) { + Iterator i; + JournalFile *f; /* This is the first invocation, hence create the * inotify watch */ @@ -2591,6 +2593,19 @@ _public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) { if (r < 0) return r; + /* Server might have done some vacuuming while we weren't watching. + Get rid of the deleted files now so they don't stay around indefinitely. */ + ORDERED_HASHMAP_FOREACH(f, j->files, i) { + r = journal_file_fstat(f); + if (r < 0) { + log_debug_errno(r,"Failed to fstat() journal file '%s' : %m", f->path); + continue; + } + + if (f->last_stat.st_nlink <= 0) + remove_file_real(j, f); + } + /* The journal might have changed since the context * object was created and we weren't watching before, * hence don't wait for anything, and return |