Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_systemd: Move one record back after skipping to the end #8917

Merged
merged 1 commit into from
Jun 6, 2024

Conversation

ardavast
Copy link
Contributor

@ardavast ardavast commented Jun 5, 2024

On recent versions of systemd, read_from_tail() doesn't work as expected unless followed with a call to sd_journal_previous().

This can be tested with: fluent-bit -i systemd -p read_from_tail=On -o stdout
The command works on:

  • Ubuntu 22.10 with systemd 251 (251.4-1ubuntu7.3)
  • Yocto mickledore with systemd 253 (253.1)

But it doesn't work on:

  • Ubuntu 24.04 with systemd 255 (255.4-1ubuntu8.1)
  • Yocto nanbield with systemd 254 (254.4)

The following short program can also be used to test this (uncomment the line that calls sd_journal_previous() to see the difference):

#include <stdio.h>
#include <stdlib.h>
#include <systemd/sd-journal.h>

int main(void) {
    sd_journal *j;
    int ret;

    sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
    sd_journal_seek_tail(j);
    //sd_journal_previous(j);

    for (;;) {
        sd_journal_wait(j, (uint64_t) -1);
        while (sd_journal_next(j) > 0) {
            const char *d;
            size_t l;

            if (sd_journal_get_data(j, "MESSAGE", (const void **)&d, &l) >= 0) {
                printf("%.*s\n", (int)l, d);
            }
        }
    }

    sd_journal_close(j);

    return 0;
}

@edsiper
Copy link
Member

edsiper commented Jun 5, 2024

@ardavast thanks for this contribution, would you please sign off the commits ? (DCO error)

@edsiper edsiper added this to the Fluent Bit v3.0.7 milestone Jun 5, 2024
Signed-off-by: Ardavast Dayleryan <ardavast@noiseoverip.com>
@ardavast
Copy link
Contributor Author

ardavast commented Jun 5, 2024

@ardavast thanks for this contribution, would you please sign off the commits ? (DCO error)

Done

Copy link
Collaborator

@leonardo-albertovich leonardo-albertovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the manual this seems to be correct :

Note that these calls do not actually make any entry the new current entry, this needs to be done in a separate step with a subsequent [sd_journal_next(3)](https://manpages.debian.org/testing/libsystemd-dev/sd_journal_next.3.en.html) invocation (or a similar call).

@edsiper edsiper merged commit 92ba3b6 into fluent:master Jun 6, 2024
44 checks passed
@n-hass
Copy link

n-hass commented Jun 20, 2024

I’m SO glad this got merged finally! This fix has existed since my PR #8396, but I was getting radio silence :( thank you so much for finally getting this merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants