From cc2293fe2e150e9a7cb1be612336fca29bc8eb1f Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Sun, 12 Jan 2025 20:26:37 -0800 Subject: [PATCH] Reset tail offset by -1 when starting and resetting journal pointer. Our journald API usage was incorrect causing our tail pointer to stick after the last received entry, causing us to receive no additional events at all. The `sd_journal_next` API states that we should always assume that we reset to the previous entry after `sd_journal_seek_tail` and this corrects the behavior that many are seeing where tallow just isn't doing anything at all. This addresses #25 from clearlinux/tallow. Tested on F41. Signed-off-by: Auke Kok --- src/tallow.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tallow.c b/src/tallow.c index 6c6459d..6989435 100644 --- a/src/tallow.c +++ b/src/tallow.c @@ -372,6 +372,7 @@ int main(void) /* go to the tail and wait */ r = sd_journal_seek_tail(j); + sd_journal_previous(j); sd_journal_wait(j, (uint64_t) 0); dbg("sd_journal_seek_tail() returned %d\n", r); while (sd_journal_next(j) != 0) @@ -388,6 +389,7 @@ int main(void) if (r == SD_JOURNAL_INVALIDATE) { fprintf(stderr, "Journal was rotated, resetting\n"); sd_journal_seek_tail(j); + sd_journal_previous(j); } else if (r == SD_JOURNAL_NOP) { dbg("Timeout reached, waiting again\n"); continue; @@ -418,6 +420,8 @@ int main(void) m = strndup(d, l+1); m[l] = '\0'; + dbg("msg %s\n", m); + struct pattern_struct *pat = patterns; while (pat) { int off[MAX_OFFSETS];