]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-journal: close journal files that were deleted by journald before we've setup...
authorMichal Sekletár <msekleta@redhat.com>
Tue, 4 Feb 2020 13:23:14 +0000 (14:23 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 5 Feb 2020 17:34:52 +0000 (18:34 +0100)
Fixes #14695

src/journal/journal-file.c
src/journal/journal-file.h
src/journal/sd-journal.c

index 505191999bd88389335a2cd23537224e12641204..bd5363586077bda3a7d3b724a70ccbe098807935 100644 (file)
@@ -601,7 +601,7 @@ static int journal_file_verify_header(JournalFile *f) {
         return 0;
 }
 
-static int journal_file_fstat(JournalFile *f) {
+int journal_file_fstat(JournalFile *f) {
         int r;
 
         assert(f);
index 502f1f567d1e653aebce8bab10c91f61b88941d5..cf0f7691fb187f933d8b39467ea56dafd88b2fc5 100644 (file)
@@ -145,6 +145,7 @@ int journal_file_open(
 int journal_file_set_offline(JournalFile *f, bool wait);
 bool journal_file_is_offlining(JournalFile *f);
 JournalFile* journal_file_close(JournalFile *j);
+int journal_file_fstat(JournalFile *f);
 DEFINE_TRIVIAL_CLEANUP_FUNC(JournalFile*, journal_file_close);
 
 int journal_file_open_reliably(
index bced8af3e3abb20208f604319b0082a095a6813b..3fa98dfda237c84ab14fe1291cd5164e24bb1095 100644 (file)
@@ -2661,6 +2661,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 */
@@ -2668,6 +2670,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