From 0488435496a9a0215fbd5c3168a53c0592df8eed Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Thu, 11 May 2017 22:18:54 +0200 Subject: [PATCH 1/2] journal: return 0 from _skip() when it didn't skip Seeking to the tail and calling `sd_journal_previous_skip(journal, 0)` was equivalent to calling it with skip == 1 (same for head and next()). --- src/journal/sd-journal.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 86afb4985d..cd56470a33 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -882,8 +882,11 @@ static int real_journal_next_skip(sd_journal *j, direction_t direction, uint64_t if (skip == 0) { /* If this is not a discrete skip, then at least * resolve the current location */ - if (j->current_location.type != LOCATION_DISCRETE) - return real_journal_next(j, direction); + if (j->current_location.type != LOCATION_DISCRETE) { + r = real_journal_next(j, direction); + if (r < 0) + return r; + } return 0; } From 5f42943c35c753148566e5887a2b9dbf982b42cf Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Thu, 11 May 2017 22:39:23 +0200 Subject: [PATCH 2/2] journalctl: honor --show-cursor in more sitatuations Try to honor --show-cursor in more situations by never terminating early when we didn't read any logs. In particular, sd_journal_previous_skip() now returns 0 when it didn't actually skip anything (for example with --lines=0), which resulted in --show-cursor not working anymore. --- src/journal/journalctl.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index f990ac9303..698a5a9dc8 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -2365,20 +2365,13 @@ int main(int argc, char *argv[]) { log_error_errno(r, "Failed to iterate through journal: %m"); goto finish; } - if (r == 0) { - if (arg_follow) - need_seek = true; - else { - if (!arg_quiet) - printf("-- No entries --\n"); - goto finish; - } - } + if (r == 0) + need_seek = true; if (!arg_follow) pager_open(arg_no_pager, arg_pager_end); - if (!arg_quiet) { + if (!arg_quiet && (arg_lines != 0 || arg_follow)) { usec_t start, end; char start_buf[FORMAT_TIMESTAMP_MAX], end_buf[FORMAT_TIMESTAMP_MAX]; @@ -2474,6 +2467,9 @@ int main(int argc, char *argv[]) { } if (!arg_follow) { + if (n_shown == 0 && !arg_quiet) + printf("-- No entries --\n"); + if (arg_show_cursor) { _cleanup_free_ char *cursor = NULL;