[systemd-devel] odd seek_tail behaviour
Sascha Kattelmann
skattelmann at tpip.net
Mon Oct 13 04:22:17 PDT 2014
Hi,
here is a related "bug" report: https://bugs.freedesktop.org/show_bug.cgi?id=64614
Doing a "next" after "seek_tail" ends up in some unexpected behaviour. Just do a "previous" after seeking the tail and everything works fine.
The problem is symmetrical: Same goes for "previous" after "seek_head". You need to do a "next" immediately after "seek_head".
I hope that will help,
Sascha
----- Original Message -----
From: "Daurnimator" <quae at daurnimator.com>
To: "systemd Mailing List" <systemd-devel at lists.freedesktop.org>
Sent: Monday, October 13, 2014 7:27:22 AM
Subject: [systemd-devel] odd seek_tail behaviour
Hi All,
I was trying to write a program that tailed the journal, but found that sd_journal_seek_tail() didn't work as expected.
That is: that it would seek to the last/most recent thing in the journal, and I could tail things from there.
I whipped up a quick demonstration program, that shows that messages I 'next' through, are before the 'cutoff':
#include <stdio.h>
#include <assert.h>
#include "systemd/sd-journal.h"
int main() {
sd_journal* j;
assert(sd_journal_open(&j, 0)==0);
uint64_t from, to;
assert(sd_journal_get_cutoff_realtime_usec(j, &from, &to)==1);
printf("CUTOFF = %llu\n", to);
printf("TAIL = %d\n", sd_journal_seek_tail(j));
for (int i=0; i<10; i++) {
printf("NEXT = %lld\n", sd_journal_next(j));
assert(sd_journal_get_realtime_usec(j, &from)==0);
printf("FOUND from %llu\n", from);
}
return 0;
}
Compiled with: gcc -std=c99 tail_logs.c -l systemd
Example output:
CUTOFF = 1413177397982789
TAIL = 0
NEXT = 1
FOUND from 1400437372012374
NEXT = 1
FOUND from 1400438753925868
NEXT = 1
FOUND from 1400438753926192
NEXT = 1
FOUND from 1400438753926257
NEXT = 1
FOUND from 1400438753926289
NEXT = 1
FOUND from 1400438753926309
NEXT = 1
FOUND from 1400438753926330
NEXT = 1
FOUND from 1400438753926353
NEXT = 1
FOUND from 1400438753926373
NEXT = 1
FOUND from 1400438753926395
Is this behaviour expected? I'm using systemd 216.
Regards,
Daurn.
_______________________________________________
systemd-devel mailing list
systemd-devel at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel
More information about the systemd-devel
mailing list