diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-10-18 03:33:44 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-10-18 03:35:58 +0200 |
commit | 15119c160268ce4ba9da4be67ed8adc412220b7d (patch) | |
tree | 17508e5e3f4ac982943ed0e02d89654c0bbc1dce | |
parent | journal: add ability to list values a specified field can take in all entries... (diff) | |
download | systemd-15119c160268ce4ba9da4be67ed8adc412220b7d.tar.xz systemd-15119c160268ce4ba9da4be67ed8adc412220b7d.zip |
journalctl: implement quering field values with new -F switch
Example:
journalctl -F _SYSTEMD_UNIT
will list all units that ever logged to the journal.
-rw-r--r-- | man/journalctl.xml | 10 | ||||
-rw-r--r-- | src/journal/journalctl.c | 47 |
2 files changed, 50 insertions, 7 deletions
diff --git a/man/journalctl.xml b/man/journalctl.xml index a533f4d0ea..4208fb4edc 100644 --- a/man/journalctl.xml +++ b/man/journalctl.xml @@ -350,6 +350,16 @@ </varlistentry> <varlistentry> + <term><option>--field=</option></term> + <term><option>-f</option></term> + + <listitem><para>Print all possible + data values the specified field can + take in all entries of the + journal.</para></listitem> + </varlistentry> + + <varlistentry> <term><option>--directory=</option></term> <term><option>-D</option></term> diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index ebb88e053e..7d954e8367 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -88,9 +88,8 @@ static enum { static int help(void) { printf("%s [OPTIONS...] [MATCH]\n\n" - "Send control commands to or query the journal.\n\n" - " -h --help Show this help\n" - " --version Show package version\n" + "Query the journal.\n\n" + "Flags:\n" " -c --cursor=CURSOR Start showing entries from specified cursor\n" " --since=DATE Start showing entries newer or of the specified date\n" " --until=DATE Stop showing entries older or of the specified date\n" @@ -107,15 +106,20 @@ static int help(void) { " --no-pager Do not pipe output into a pager\n" " -m --merge Show entries from all available journals\n" " -D --directory=PATH Show journal files from directory\n" - "Commands:\n" +#ifdef HAVE_GCRYPT + " --interval=TIME Time interval for changing the FSS sealing key\n" + " --verify-key=KEY Specify FSS verification key\n" +#endif + "\nCommands:\n" + " -h --help Show this help\n" + " --version Show package version\n" " --new-id128 Generate a new 128 Bit ID\n" " --header Show journal header information\n" " --disk-usage Show total disk usage\n" + " -F --field=FIELD List all values a certain field takes\n" #ifdef HAVE_GCRYPT " --setup-keys Generate new FSS key pair\n" - " --interval=TIME Time interval for changing the FSS sealing key\n" " --verify Verify journal file consistency\n" - " --verify-key=KEY Specify FSS verification key\n" #endif , program_invocation_short_name); @@ -164,6 +168,7 @@ static int parse_argv(int argc, char *argv[]) { { "since", required_argument, NULL, ARG_SINCE }, { "until", required_argument, NULL, ARG_UNTIL }, { "unit", required_argument, NULL, 'u' }, + { "field", required_argument, NULL, 'F' }, { NULL, 0, NULL, 0 } }; @@ -172,7 +177,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:", options, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hfo:an::qmbD:p:c:u:F:", options, NULL)) >= 0) { switch (c) { @@ -369,6 +374,10 @@ static int parse_argv(int argc, char *argv[]) { case '?': return -EINVAL; + case 'F': + arg_field = optarg; + break; + default: log_error("Unknown option code %c", c); return -EINVAL; @@ -898,6 +907,30 @@ int main(int argc, char *argv[]) { if (r < 0) goto finish; + if (arg_field) { + const void *data; + size_t size; + + r = sd_journal_query_unique(j, arg_field); + if (r < 0) { + log_error("Failed to query unique data objects: %s", strerror(-r)); + goto finish; + } + + SD_JOURNAL_FOREACH_UNIQUE(j, data, size) { + const void *eq; + + eq = memchr(data, '=', size); + if (eq) + printf("%.*s\n", (int) (size - ((const uint8_t*) eq - (const uint8_t*) data + 1)), (const char*) eq + 1); + else + printf("%.*s\n", (int) size, (const char*) data); + } + + r = 0; + goto finish; + } + if (arg_cursor) { r = sd_journal_seek_cursor(j, arg_cursor); if (r < 0) { |