X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fcoredumpctl.c;h=b82c6f45301967c424a2284dd97d5b5be9f9c5de;hb=31938a8560a664c32a9d72f1fc2d4347b232e6e9;hp=d1450c09a28df907f772a9866fd58a1ac7dcc6cd;hpb=31cda3d1759dee3e48c8ed4a949d99f041bdca1c;p=elogind.git diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index d1450c09a..b82c6f453 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" @@ -58,7 +58,7 @@ static Set *new_matches(void) { char *tmp; int r; - set = set_new(trivial_hash_func, trivial_compare_func); + set = set_new(NULL); if (!set) { log_oom(); return NULL; @@ -73,7 +73,7 @@ static Set *new_matches(void) { r = set_consume(set, tmp); if (r < 0) { - log_error("failed to add to set: %s", strerror(-r)); + log_error_errno(r, "failed to add to set: %m"); set_free(set); return NULL; } @@ -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,20 +108,38 @@ 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_errno(r, "Failed to add pattern: %m"); goto fail; } return 0; fail: - log_error("Failed to add match: %s", strerror(-r)); + log_error_errno(r, "Failed to add match: %m"); 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; @@ -331,7 +327,7 @@ static int print_list(FILE* file, sd_journal *j, int had_legend) { r = sd_journal_get_realtime_usec(j, &t); if (r < 0) { - log_error("Failed to get realtime timestamp: %s", strerror(-r)); + log_error_errno(r, "Failed to get realtime timestamp: %m"); return r; } @@ -526,7 +522,7 @@ static int focus(sd_journal *j) { if (r == 0) r = sd_journal_previous(j); if (r < 0) { - log_error("Failed to search journal: %s", strerror(-r)); + log_error_errno(r, "Failed to search journal: %m"); return r; } if (r == 0) { @@ -590,7 +586,7 @@ static int save_core(sd_journal *j, int fd, char **path, bool *unlink_temp) { * compressed file (probably uncached). */ r = sd_journal_get_data(j, "COREDUMP_FILENAME", (const void**) &data, &len); if (r < 0 && r != -ENOENT) - log_warning("Failed to retrieve COREDUMP_FILENAME: %s", strerror(-r)); + log_warning_errno(r, "Failed to retrieve COREDUMP_FILENAME: %m"); else if (r == 0) retrieve(data, len, "COREDUMP_FILENAME", &filename); @@ -659,7 +655,7 @@ static int save_core(sd_journal *j, int fd, char **path, bool *unlink_temp) { r = decompress_stream(filename, fdf, fd, -1); if (r < 0) { - log_error("Failed to decompress %s: %s", filename, strerror(-r)); + log_error_errno(r, "Failed to decompress %s: %m", filename); goto error; } #else @@ -671,7 +667,7 @@ static int save_core(sd_journal *j, int fd, char **path, bool *unlink_temp) { if (r == -ENOENT) log_error("Cannot retrieve coredump from journal nor disk."); else - log_error("Failed to retrieve COREDUMP field: %s", strerror(-r)); + log_error_errno(r, "Failed to retrieve COREDUMP field: %m"); goto error; } @@ -709,7 +705,7 @@ static int dump_core(sd_journal* j) { r = save_core(j, output ? fileno(output) : STDOUT_FILENO, NULL, NULL); if (r < 0) { - log_error("Coredump retrieval failed: %s", strerror(-r)); + log_error_errno(r, "Coredump retrieval failed: %m"); return r; } @@ -740,7 +736,7 @@ static int run_gdb(sd_journal *j) { r = sd_journal_get_data(j, "COREDUMP_EXE", (const void**) &data, &len); if (r < 0) { - log_error("Failed to retrieve COREDUMP_EXE field: %s", strerror(-r)); + log_error_errno(r, "Failed to retrieve COREDUMP_EXE field: %m"); return r; } @@ -764,7 +760,7 @@ static int run_gdb(sd_journal *j) { r = save_core(j, -1, &path, &unlink_path); if (r < 0) { - log_error("Failed to retrieve core: %s", strerror(-r)); + log_error_errno(r, "Failed to retrieve core: %m"); return r; } @@ -824,7 +820,7 @@ int main(int argc, char *argv[]) { r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); if (r < 0) { - log_error("Failed to open journal: %s", strerror(-r)); + log_error_errno(r, "Failed to open journal: %m"); goto end; }