X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fcoredumpctl.c;h=3bceb48ff731351afb2dff3c9d9d675ad4da44e6;hb=020d59000f86b3d98be763eaee6a2671f0427e46;hp=e1bd8621e32c9023f26ff0d59f392305fd9c7599;hpb=2927b326ccf67236e148444679f582ea1437ef5a;p=elogind.git diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index e1bd8621e..3bceb48ff 100644 --- a/src/journal/coredumpctl.c +++ b/src/journal/coredumpctl.c @@ -126,10 +126,11 @@ static int add_match(Set *set, const char *match) { goto fail; log_debug("Adding pattern: %s", pattern); - r = set_consume(set, pattern); + r = set_put(set, pattern); if (r < 0) { log_error("Failed to add pattern '%s': %s", pattern, strerror(-r)); + free(pattern); goto fail; } @@ -155,7 +156,7 @@ 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' }, - { NULL, 0, NULL, 0 } + {} }; assert(argc >= 0); @@ -163,15 +164,15 @@ static int parse_argv(int argc, char *argv[], Set *matches) { while ((c = getopt_long(argc, argv, "ho:F:", options, NULL)) >= 0) switch(c) { + case 'h': - help(); arg_action = ACTION_NONE; - return 0; + return help(); case ARG_VERSION: + arg_action = ACTION_NONE; puts(PACKAGE_STRING); puts(SYSTEMD_FEATURES); - arg_action = ACTION_NONE; return 0; case ARG_NO_PAGER: @@ -209,13 +210,12 @@ static int parse_argv(int argc, char *argv[], Set *matches) { return -EINVAL; default: - log_error("Unknown option code %c", c); - return -EINVAL; + assert_not_reached("Unhandled option"); } if (optind < argc) { const char *cmd = argv[optind++]; - if(streq(cmd, "list")) + if (streq(cmd, "list")) arg_action = ACTION_LIST; else if (streq(cmd, "dump")) arg_action = ACTION_DUMP; @@ -342,7 +342,7 @@ static int dump_list(sd_journal *j) { assert(j); /* The coredumps are likely to compressed, and for just - * listing them we don#t need to decompress them, so let's + * listing them we don't need to decompress them, so let's * pick a fairly low data threshold here */ sd_journal_set_data_threshold(j, 4096); @@ -417,7 +417,7 @@ static int dump_core(sd_journal* j) { r = sd_journal_previous(j); if (r >= 0) - log_warning("More than one entry matches, ignoring rest.\n"); + log_warning("More than one entry matches, ignoring rest."); return 0; } @@ -472,7 +472,7 @@ static int run_gdb(sd_journal *j) { data = (const uint8_t*) data + 9; len -= 9; - fd = mkostemp(path, O_WRONLY); + fd = mkostemp_safe(path, O_WRONLY|O_CLOEXEC); if (fd < 0) { log_error("Failed to create temporary file: %m"); return -errno; @@ -480,7 +480,7 @@ static int run_gdb(sd_journal *j) { sz = write(fd, data, len); if (sz < 0) { - log_error("Failed to write temporary file: %s", strerror(errno)); + log_error("Failed to write temporary file: %m"); r = -errno; goto finish; } @@ -557,6 +557,13 @@ int main(int argc, char *argv[]) { } } + if (_unlikely_(log_get_max_level() >= LOG_PRI(LOG_DEBUG))) { + _cleanup_free_ char *filter; + + filter = journal_make_match_string(j); + log_debug("Journal filter: %s", filter); + } + switch(arg_action) { case ACTION_LIST: