summaryrefslogtreecommitdiff
path: root/src/journal
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2023-03-09 16:51:24 +0800
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-03-09 21:36:12 +0900
commit5d2ab010dff42ccd5281c2b7ff60c4551fbcfbdf (patch)
treea48db54ae4b83da9dea6ae71e60c13e6b3965257 /src/journal
parentb2d3e2a0dc39313a46feb9194114c5554bacb0d9 (diff)
downloadsystemd-5d2ab010dff42ccd5281c2b7ff60c4551fbcfbdf.tar.gz
journalctl: fix when --since, --until and --lines are used altogether
This is a follow-up for #26669 (81fb5375b3b3bfc22d023d7908ad9eee4b3c1ffb). After the mentioned commit, we stopped checking if the entry is within the range of --until if --lines is used. However, when --since, --until and --lines=N are used altogether, and the number of lines between --since and --until is smaller than N, we would seek to --since later (f58269510727964cb5c10e7d2f9849c442ea1f80). This breaks the assumption that if --lines is set, the boundary is never exceeded because the counter of outputs gets us covered.
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/journalctl.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index b2951ed1b1..59736143bc 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -2567,7 +2567,12 @@ static int run(int argc, char *argv[]) {
break;
}
- if (arg_until_set && !arg_reverse && arg_lines < 0) {
+ if (arg_until_set && !arg_reverse && (arg_lines < 0 || arg_since_set)) {
+ /* If --lines= is set, we usually rely on the n_shown to tell us
+ * when to stop. However, if --since= is set too, we may end up
+ * having less than --lines= to output. In this case let's also
+ * check if the entry is in range. */
+
usec_t usec;
r = sd_journal_get_realtime_usec(j, &usec);