X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fjournal%2Fcoredumpctl.c;h=34dcae87c0c48b8e2395c2bec3d40358735e8961;hp=5d6b2c7adff9fbd6c684b12e673133d68e5692b3;hb=48d4c7468fb5003ae45ac834de1ca85624cdd56e;hpb=d89c8fdf48c7bad5816b9f2e77e8361721f22517 diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index 5d6b2c7ad..34dcae87c 100644 --- a/src/journal/coredumpctl.c +++ b/src/journal/coredumpctl.c @@ -26,7 +26,7 @@ #include #include -#include +#include "systemd/sd-journal.h" #include "build.h" #include "set.h" @@ -81,29 +81,6 @@ static Set *new_matches(void) { return set; } -static int help(void) { - - printf("%s [OPTIONS...]\n\n" - "List or retrieve coredumps from the journal.\n\n" - "Flags:\n" - " -h --help Show this help\n" - " --version Print version string\n" - " --no-pager Do not pipe output into a pager\n" - " --no-legend Do not print the column headers.\n" - " -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" - - "Commands:\n" - " list [MATCHES...] List available coredumps (default)\n" - " info [MATCHES...] Show detailed information about one or more coredumps\n" - " dump [MATCHES...] Print first matching coredump to stdout\n" - " gdb [MATCHES...] Start gdb for the first matching coredump\n" - , program_invocation_short_name); - - return 0; -} - static int add_match(Set *set, const char *match) { int r = -ENOMEM; unsigned pid; @@ -131,11 +108,9 @@ static int add_match(Set *set, const char *match) { goto fail; log_debug("Adding pattern: %s", pattern); - r = set_put(set, pattern); + r = set_consume(set, pattern); if (r < 0) { - log_error("Failed to add pattern '%s': %s", - pattern, strerror(-r)); - free(pattern); + log_error("Failed to add pattern: %s", strerror(-r)); goto fail; } @@ -145,6 +120,26 @@ fail: return r; } +static void help(void) { + printf("%s [OPTIONS...]\n\n" + "List or retrieve coredumps from the journal.\n\n" + "Flags:\n" + " -h --help Show this help\n" + " --version Print version string\n" + " --no-pager Do not pipe output into a pager\n" + " --no-legend Do not print the column headers.\n" + " -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" + + "Commands:\n" + " list [MATCHES...] List available coredumps (default)\n" + " info [MATCHES...] Show detailed information about one or more coredumps\n" + " dump [MATCHES...] Print first matching coredump to stdout\n" + " gdb [MATCHES...] Start gdb for the first matching coredump\n" + , program_invocation_short_name); +} + static int parse_argv(int argc, char *argv[], Set *matches) { enum { ARG_VERSION = 0x100, @@ -172,7 +167,8 @@ static int parse_argv(int argc, char *argv[], Set *matches) { case 'h': arg_action = ACTION_NONE; - return help(); + help(); + return 0; case ARG_VERSION: arg_action = ACTION_NONE; @@ -595,7 +591,8 @@ static int save_core(sd_journal *j, int fd, char **path, bool *unlink_temp) { retrieve(data, len, "COREDUMP_FILENAME", &filename); if (filename && access(filename, R_OK) < 0) { - log_debug("File %s is not readable: %m", filename); + log_full(errno == ENOENT ? LOG_DEBUG : LOG_WARNING, + "File %s is not readable: %m", filename); free(filename); filename = NULL; } @@ -668,7 +665,7 @@ static int save_core(sd_journal *j, int fd, char **path, bool *unlink_temp) { #endif } else { if (r == -ENOENT) - log_error("Coredump neither in journal file nor stored externally on disk."); + log_error("Cannot retrieve coredump from journal nor disk."); else log_error("Failed to retrieve COREDUMP field: %s", strerror(-r)); goto error;