From 8f14c8327b1c2b578bbf1235723a77931c3d0223 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 27 Sep 2012 23:25:23 +0200 Subject: [PATCH] journalctl: add --cursor switch --- man/journalctl.xml | 9 +++++++++ src/journal/journalctl.c | 21 +++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/man/journalctl.xml b/man/journalctl.xml index 50c915d59..651a8a56a 100644 --- a/man/journalctl.xml +++ b/man/journalctl.xml @@ -254,6 +254,15 @@ current boot. + + + + + Jump to the location + in the journal specified by the passed + cursor. + + diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 62bdcb7c6..bac872949 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -63,6 +63,7 @@ static bool arg_no_tail = false; static bool arg_quiet = false; static bool arg_merge = false; static bool arg_this_boot = false; +static const char *arg_cursor = NULL; static const char *arg_directory = NULL; static int arg_priorities = 0xFF; static const char *arg_verify_key = NULL; @@ -87,6 +88,7 @@ static int help(void) { " --version Show package version\n" " --no-pager Do not pipe output into a pager\n" " -a --all Show all fields, including long and unprintable\n" + " -c --cursor=CURSOR Jump to the specified cursor\n" " -f --follow Follow journal\n" " -n --lines[=INTEGER] Number of journal entries to show\n" " --no-tail Show all lines, even in follow mode\n" @@ -148,6 +150,7 @@ static int parse_argv(int argc, char *argv[]) { { "verify", no_argument, NULL, ARG_VERIFY }, { "verify-key", required_argument, NULL, ARG_VERIFY_KEY }, { "disk-usage", no_argument, NULL, ARG_DISK_USAGE }, + { "cursor", no_argument, NULL, 'c' }, { NULL, 0, NULL, 0 } }; @@ -156,7 +159,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "hfo:an::qmbD:p:", options, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hfo:an::qmbD:p:c:", options, NULL)) >= 0) { switch (c) { @@ -228,6 +231,10 @@ static int parse_argv(int argc, char *argv[]) { arg_directory = optarg; break; + case 'c': + arg_cursor = optarg; + break; + case ARG_HEADER: arg_action = ACTION_PRINT_HEADER; break; @@ -829,7 +836,16 @@ int main(int argc, char *argv[]) { } } - if (arg_lines >= 0) { + if (arg_cursor) { + r = sd_journal_seek_cursor(j, arg_cursor); + if (r < 0) { + log_error("Failed to seek to cursor: %s", strerror(-r)); + goto finish; + } + + r = sd_journal_next(j); + + } else if (arg_lines >= 0) { r = sd_journal_seek_tail(j); if (r < 0) { log_error("Failed to seek to tail: %s", strerror(-r)); @@ -837,6 +853,7 @@ int main(int argc, char *argv[]) { } r = sd_journal_previous_skip(j, arg_lines); + } else { r = sd_journal_seek_head(j); if (r < 0) { -- 2.30.2