From b73e9a024b1533ec0e7ecc1fa4996d0f520eb4de Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Tue, 25 Aug 2015 10:36:49 +0200 Subject: coredumpctl: Add --directory option for reading alternate journal In the Cockpit integration tests we hang onton the journal files for a failed test and would like to inspect them using coredumpctl. This commit adds the ability to specify an alternate directory for coredumpctl to read the journal from. --- man/coredumpctl.xml | 8 ++++++++ src/journal/coredumpctl.c | 25 ++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/man/coredumpctl.xml b/man/coredumpctl.xml index efbc655a76..1bcc984cc5 100644 --- a/man/coredumpctl.xml +++ b/man/coredumpctl.xml @@ -102,6 +102,14 @@ + + DIR + DIR + + Use the journal files in the specified . + + + diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index 098f62af50..644ba91b0d 100644 --- a/src/journal/coredumpctl.c +++ b/src/journal/coredumpctl.c @@ -49,6 +49,7 @@ static enum { ACTION_GDB, } arg_action = ACTION_LIST; static const char* arg_field = NULL; +static const char *arg_directory = NULL; static int arg_no_pager = false; static int arg_no_legend = false; static int arg_one = false; @@ -131,6 +132,7 @@ static void help(void) { " -1 Show information about most recent entry only\n" " -F --field=FIELD List all values a certain field takes\n" " -o --output=FILE Write output to FILE\n\n" + " -D --directory=DIR Use journal files from directory\n\n" "Commands:\n" " list [MATCHES...] List available coredumps (default)\n" @@ -156,13 +158,14 @@ static int parse_argv(int argc, char *argv[], Set *matches) { { "no-legend", no_argument, NULL, ARG_NO_LEGEND }, { "output", required_argument, NULL, 'o' }, { "field", required_argument, NULL, 'F' }, + { "directory", required_argument, NULL, 'D' }, {} }; assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "ho:F:1", options, NULL)) >= 0) + while ((c = getopt_long(argc, argv, "ho:F:1D:", options, NULL)) >= 0) switch(c) { case 'h': @@ -208,6 +211,10 @@ static int parse_argv(int argc, char *argv[], Set *matches) { arg_one = true; break; + case 'D': + arg_directory = optarg; + break; + case '?': return -EINVAL; @@ -808,10 +815,18 @@ int main(int argc, char *argv[]) { sigbus_install(); - r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); - if (r < 0) { - log_error_errno(r, "Failed to open journal: %m"); - goto end; + if (arg_directory) { + r = sd_journal_open_directory(&j, arg_directory, 0); + if (r < 0) { + log_error_errno(r, "Failed to open journals in directory: %s: %m", arg_directory); + goto end; + } + } else { + r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); + if (r < 0) { + log_error_errno(r, "Failed to open journal: %m"); + goto end; + } } /* We want full data, nothing truncated. */ -- cgit v1.2.3-54-g00ecf From f6a4dae6a57fcef3bb2a082f6479dd59aaf5b471 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 25 Aug 2015 20:04:55 +0200 Subject: man: minor fixes to coredumpctl(1) --- man/coredumpctl.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/man/coredumpctl.xml b/man/coredumpctl.xml index 1bcc984cc5..0f1afe77c3 100644 --- a/man/coredumpctl.xml +++ b/man/coredumpctl.xml @@ -86,8 +86,8 @@ - - + FIELD + FIELD Print all possible data values the specified field takes in matching coredump entries of the @@ -95,8 +95,8 @@ - - + FILE + FILE Write the core to . @@ -140,7 +140,7 @@ Extract the last coredump matching specified characteristics. The coredump will be written on standard output, unless an output file is specified with - . + . -- cgit v1.2.3-54-g00ecf