Compare commits

...

2 Commits

Author SHA1 Message Date
Anita Zhang a3af963958
Merge pull request #15414 from mrc0mmand/coredumpctl-file
coredumpctl: support --file=PATH
2020-04-13 13:54:24 -07:00
Frantisek Sumsal aeb5645082 coredumpctl: support --file=PATH
Let's match journalctl's functionality by throwing --file for
coredumpctl into the mix, so we can work on a single journal file
as well.
2020-04-13 17:10:27 +02:00
2 changed files with 29 additions and 0 deletions

View File

@ -217,6 +217,17 @@
will be used. </para></listitem> will be used. </para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>--file=<replaceable>GLOB</replaceable></option></term>
<listitem><para>Takes a file glob as an argument. If
specified, coredumpctl will operate on the specified journal
files matching <replaceable>GLOB</replaceable> instead of the
default runtime and system journal paths. May be specified
multiple times, in which case files will be suitably
interleaved.</para></listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>-D</option> <replaceable>DIR</replaceable></term> <term><option>-D</option> <replaceable>DIR</replaceable></term>
<term><option>--directory=</option><replaceable>DIR</replaceable></term> <term><option>--directory=</option><replaceable>DIR</replaceable></term>

View File

@ -17,6 +17,7 @@
#include "def.h" #include "def.h"
#include "fd-util.h" #include "fd-util.h"
#include "fs-util.h" #include "fs-util.h"
#include "glob-util.h"
#include "journal-internal.h" #include "journal-internal.h"
#include "journal-util.h" #include "journal-util.h"
#include "log.h" #include "log.h"
@ -44,6 +45,7 @@ static usec_t arg_since = USEC_INFINITY, arg_until = USEC_INFINITY;
static const char* arg_field = NULL; static const char* arg_field = NULL;
static const char *arg_debugger = NULL; static const char *arg_debugger = NULL;
static const char *arg_directory = NULL; static const char *arg_directory = NULL;
static char **arg_file = NULL;
static PagerFlags arg_pager_flags = 0; static PagerFlags arg_pager_flags = 0;
static int arg_no_legend = false; static int arg_no_legend = false;
static int arg_one = false; static int arg_one = false;
@ -51,6 +53,8 @@ static const char* arg_output = NULL;
static bool arg_reverse = false; static bool arg_reverse = false;
static bool arg_quiet = false; static bool arg_quiet = false;
STATIC_DESTRUCTOR_REGISTER(arg_file, strv_freep);
static int add_match(sd_journal *j, const char *match) { static int add_match(sd_journal *j, const char *match) {
_cleanup_free_ char *p = NULL; _cleanup_free_ char *p = NULL;
const char* prefix, *pattern; const char* prefix, *pattern;
@ -111,6 +115,10 @@ static int acquire_journal(sd_journal **ret, char **matches) {
r = sd_journal_open_directory(&j, arg_directory, 0); r = sd_journal_open_directory(&j, arg_directory, 0);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to open journals in directory: %s: %m", arg_directory); return log_error_errno(r, "Failed to open journals in directory: %s: %m", arg_directory);
} else if (arg_file) {
r = sd_journal_open_files(&j, (const char**)arg_file, 0);
if (r < 0)
return log_error_errno(r, "Failed to open journal files: %m");
} else { } else {
r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
if (r < 0) if (r < 0)
@ -164,6 +172,7 @@ static int help(void) {
" -r --reverse Show the newest entries first\n" " -r --reverse Show the newest entries first\n"
" -F --field=FIELD List all values a certain field takes\n" " -F --field=FIELD List all values a certain field takes\n"
" -o --output=FILE Write output to FILE\n" " -o --output=FILE Write output to FILE\n"
" --file=PATH Use journal file\n"
" -D --directory=DIR Use journal files from directory\n\n" " -D --directory=DIR Use journal files from directory\n\n"
" -q --quiet Do not show info messages and privilege warning\n" " -q --quiet Do not show info messages and privilege warning\n"
"\nSee the %s for details.\n" "\nSee the %s for details.\n"
@ -182,6 +191,7 @@ static int parse_argv(int argc, char *argv[]) {
ARG_NO_PAGER, ARG_NO_PAGER,
ARG_NO_LEGEND, ARG_NO_LEGEND,
ARG_DEBUGGER, ARG_DEBUGGER,
ARG_FILE,
}; };
int c, r; int c, r;
@ -194,6 +204,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "debugger", required_argument, NULL, ARG_DEBUGGER }, { "debugger", required_argument, NULL, ARG_DEBUGGER },
{ "output", required_argument, NULL, 'o' }, { "output", required_argument, NULL, 'o' },
{ "field", required_argument, NULL, 'F' }, { "field", required_argument, NULL, 'F' },
{ "file", required_argument, NULL, ARG_FILE },
{ "directory", required_argument, NULL, 'D' }, { "directory", required_argument, NULL, 'D' },
{ "reverse", no_argument, NULL, 'r' }, { "reverse", no_argument, NULL, 'r' },
{ "since", required_argument, NULL, 'S' }, { "since", required_argument, NULL, 'S' },
@ -225,6 +236,12 @@ static int parse_argv(int argc, char *argv[]) {
arg_debugger = optarg; arg_debugger = optarg;
break; break;
case ARG_FILE:
r = glob_extend(&arg_file, optarg);
if (r < 0)
return log_error_errno(r, "Failed to add paths: %m");
break;
case 'o': case 'o':
if (arg_output) if (arg_output)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
@ -1096,6 +1113,7 @@ static int run(int argc, char *argv[]) {
ansi_highlight_red(), ansi_highlight_red(),
units_active, units_active == 1 ? "unit is running" : "units are running", units_active, units_active == 1 ? "unit is running" : "units are running",
ansi_normal()); ansi_normal());
return r; return r;
} }