mirror of
https://github.com/systemd/systemd.git
synced 2024-11-27 04:03:36 +08:00
Merge pull request #31861 from yuwata/journalctl-fix-until
journalctl: make --until work again with --after-cursor and --lines
This commit is contained in:
commit
16f5baa247
@ -2070,6 +2070,7 @@ static int update_cursor(sd_journal *j) {
|
||||
|
||||
typedef struct Context {
|
||||
sd_journal *journal;
|
||||
bool has_cursor;
|
||||
bool need_seek;
|
||||
bool since_seeked;
|
||||
bool ellipsized;
|
||||
@ -2099,11 +2100,11 @@ static int show(Context *c) {
|
||||
break;
|
||||
}
|
||||
|
||||
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. */
|
||||
if (arg_until_set && !arg_reverse && (arg_lines < 0 || arg_since_set || c->has_cursor)) {
|
||||
/* If --lines= is set, we usually rely on the n_shown to tell us when to stop.
|
||||
* However, if --since= or one of the cursor argument 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;
|
||||
|
||||
@ -2712,6 +2713,7 @@ static int run(int argc, char *argv[]) {
|
||||
|
||||
Context c = {
|
||||
.journal = j,
|
||||
.has_cursor = cursor,
|
||||
.need_seek = need_seek,
|
||||
.since_seeked = since_seeked,
|
||||
};
|
||||
|
@ -275,3 +275,11 @@ hello
|
||||
world
|
||||
EOF
|
||||
rm -f "$CURSOR_FILE"
|
||||
|
||||
# Check that --until works with --after-cursor and --lines/-n
|
||||
# See: https://github.com/systemd/systemd/issues/31776
|
||||
CURSOR_FILE="$(mktemp)"
|
||||
journalctl -q -n 0 --cursor-file="$CURSOR_FILE"
|
||||
TIMESTAMP="$(journalctl -q -n 1 --cursor="$(<"$CURSOR_FILE")" --output=short-unix | cut -d ' ' -f 1 | cut -d '.' -f 1)"
|
||||
[[ -z "$(journalctl -q -n 10 --after-cursor="$(<"$CURSOR_FILE")" --until "@$((TIMESTAMP - 3))")" ]]
|
||||
rm -f "$CURSOR_FILE"
|
||||
|
Loading…
Reference in New Issue
Block a user