X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournalctl.c;h=65114b2ff8a219711c56d5d1adc4ba9bf41f5d7e;hb=7199aa96ce19468d9ce4cb21a13e32a3792fde41;hp=c90fecd239e5bc641ea01068569a3361d5363f46;hpb=99613ec5d7f0c6e30801457f60c2cab7d8e50d8d;p=elogind.git diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index c90fecd23..65114b2ff 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -38,6 +38,7 @@ #include #include "log.h" +#include "logs-show.h" #include "util.h" #include "path-util.h" #include "build.h" @@ -56,6 +57,7 @@ #define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE) static OutputMode arg_output = OUTPUT_SHORT; +static bool arg_pager_end = false; static bool arg_follow = false; static bool arg_full = false; static bool arg_all = false; @@ -75,7 +77,7 @@ static usec_t arg_interval = DEFAULT_FSS_INTERVAL_USEC; static usec_t arg_since, arg_until; static bool arg_since_set = false, arg_until_set = false; static const char *arg_unit = NULL; -static const char *arg_unit_type = NULL; +static bool arg_unit_system; static const char *arg_field = NULL; static bool arg_catalog = false; static bool arg_reverse = false; @@ -103,6 +105,7 @@ static int help(void) { " -u --unit=UNIT Show data only from the specified unit\n" " --user-unit=UNIT Show data only from the specified user session unit\n" " -p --priority=RANGE Show only messages within the specified priority range\n" + " -e --pager-end Immediately jump to end of the journal in the pager\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" @@ -163,6 +166,7 @@ static int parse_argv(int argc, char *argv[]) { { "help", no_argument, NULL, 'h' }, { "version" , no_argument, NULL, ARG_VERSION }, { "no-pager", no_argument, NULL, ARG_NO_PAGER }, + { "pager-end", no_argument, NULL, 'e' }, { "follow", no_argument, NULL, 'f' }, { "output", required_argument, NULL, 'o' }, { "all", no_argument, NULL, 'a' }, @@ -184,8 +188,8 @@ static int parse_argv(int argc, char *argv[]) { { "cursor", required_argument, NULL, 'c' }, { "since", required_argument, NULL, ARG_SINCE }, { "until", required_argument, NULL, ARG_UNTIL }, - { "user-unit", required_argument, NULL, ARG_USER_UNIT }, { "unit", required_argument, NULL, 'u' }, + { "user-unit", required_argument, NULL, ARG_USER_UNIT }, { "field", required_argument, NULL, 'F' }, { "catalog", no_argument, NULL, 'x' }, { "list-catalog", no_argument, NULL, ARG_LIST_CATALOG }, @@ -199,7 +203,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "hfo:an::qmbD:p:c:u:F:xr", options, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hefo:an::qmbD:p:c:u:F:xr", options, NULL)) >= 0) { switch (c) { @@ -216,6 +220,14 @@ static int parse_argv(int argc, char *argv[]) { arg_no_pager = true; break; + case 'e': + arg_pager_end = true; + + if (arg_lines < 0) + arg_lines = 1000; + + break; + case 'f': arg_follow = true; break; @@ -408,14 +420,14 @@ static int parse_argv(int argc, char *argv[]) { arg_until_set = true; break; - case ARG_USER_UNIT: + case 'u': arg_unit = optarg; - arg_unit_type = "_SYSTEMD_USER_UNIT="; + arg_unit_system = true; break; - case 'u': + case ARG_USER_UNIT: arg_unit = optarg; - arg_unit_type = "_SYSTEMD_UNIT="; + arg_unit_system = false; break; case '?': @@ -593,16 +605,12 @@ static int add_unit(sd_journal *j) { if (!u) return log_oom(); - m = strappend(arg_unit_type, u); - - if (!m) - return log_oom(); - - r = sd_journal_add_match(j, m, strlen(m)); - if (r < 0) { - log_error("Failed to add match: %s", strerror(-r)); + if (arg_unit_system) + r = add_matches_for_unit(j, u); + else + r = add_matches_for_user_unit(j, u, getuid()); + if (r < 0) return r; - } return 0; } @@ -1075,7 +1083,7 @@ int main(int argc, char *argv[]) { } if (!arg_no_pager && !arg_follow) - pager_open(); + pager_open(arg_pager_end); if (!arg_quiet) { usec_t start, end;