Skip to content

Commit

Permalink
Reset tail offset by -1 when starting and resetting journal pointer.
Browse files Browse the repository at this point in the history
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 clearlinux#25 from clearlinux/tallow. Tested on F41.

Signed-off-by: Auke Kok <[email protected]>
  • Loading branch information
sofar committed Jan 13, 2025
1 parent e944c7b commit cc2293f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/tallow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit cc2293f

Please sign in to comment.