803fb7
From ca55fb67bc81313edf0aa6523b6f9ffce50ecdda Mon Sep 17 00:00:00 2001
803fb7
From: Michal Sekletar <msekletar@users.noreply.github.com>
803fb7
Date: Mon, 24 Apr 2017 18:33:12 +0200
803fb7
Subject: [PATCH] sd-journal: return SD_JOURNAL_INVALIDATE only if journal
803fb7
 files were actually deleted/moved (#5580)
803fb7
803fb7
When caller invokes sd_journal_open() we usually open at least one
803fb7
directory with journal files. add_root_directory() function increments
803fb7
current_invalidate_counter. After sd_journal_open() returns
803fb7
current_invalidate_counter != last_invalidate_counter.
803fb7
803fb7
After caller waits for journal events (e.g. waits for new messages in
803fb7
journal) then it usually calls sd_journal_process(). However, on first
803fb7
call to sd_journal_process(), function determine_change() returns
803fb7
SD_JOURNAL_INVALIDATE even though no journal files were
803fb7
deleted/moved. This is because current_invalidate_counter !=
803fb7
last_invalidate_counter.
803fb7
803fb7
After the fix we make sure counters has the same value before we begin
803fb7
processing inotify events.
803fb7
803fb7
(cherry picked from commit f934644424daa6c86fd2284fe8f33ea233ece874)
803fb7
803fb7
Resolves: #1446140
803fb7
---
803fb7
 src/journal/sd-journal.c | 1 +
803fb7
 1 file changed, 1 insertion(+)
803fb7
803fb7
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
803fb7
index 20456c3a1..72f312b67 100644
803fb7
--- a/src/journal/sd-journal.c
803fb7
+++ b/src/journal/sd-journal.c
803fb7
@@ -2190,6 +2190,7 @@ _public_ int sd_journal_process(sd_journal *j) {
803fb7
         assert_return(!journal_pid_changed(j), -ECHILD);
803fb7
 
803fb7
         j->last_process_usec = now(CLOCK_MONOTONIC);
803fb7
+        j->last_invalidate_counter = j->current_invalidate_counter;
803fb7
 
803fb7
         for (;;) {
803fb7
                 union inotify_event_buffer buffer;