From d6720eec30e42f263b0d311b107b752979517717 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 14 Oct 2014 15:04:31 +0200 Subject: call sd_journal_{seek_tail,previous}() before adding matches I had some trouble with the code jumping to older entries. Possibly this was caused by adding matches too early. --- journal-notify.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/journal-notify.c b/journal-notify.c index 0dbb83a..f733477 100644 --- a/journal-notify.c +++ b/journal-notify.c @@ -100,6 +100,18 @@ int main(int argc, char **argv) { goto out10; } + /* seek to the end of the journal */ + if ((rc = sd_journal_seek_tail(journal)) < 0) { + fprintf(stderr, "Failed to seek to the tail: %s\n", strerror(-rc)); + goto out30; + } + + /* we are behind the last entry, so use previous one */ + if ((rc = sd_journal_previous(journal)) < 0) { + fprintf(stderr, "Failed to iterate to previous entry: %s\n", strerror(-rc)); + goto out30; + } + /* get command line options - part II*/ while ((i = getopt_long(argc, argv, optstring, options_long, NULL)) != -1) { switch (i) { @@ -156,18 +168,6 @@ int main(int argc, char **argv) { } } - /* seek to the end of the journal */ - if ((rc = sd_journal_seek_tail(journal)) < 0) { - fprintf(stderr, "Failed to seek to the tail: %s\n", strerror(-rc)); - goto out30; - } - - /* we are behind the last entry, so use previous one */ - if ((rc = sd_journal_previous(journal)) < 0) { - fprintf(stderr, "Failed to iterate to previous entry: %s\n", strerror(-rc)); - goto out30; - } - if (notify_init(program) == FALSE) { fprintf(stderr, "Failed to initialize notify.\n"); rc = EXIT_FAILURE; -- cgit v1.2.3-54-g00ecf