X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fcoredumpctl.c;h=2b24ff8a94f579d09a6f9323f9e9cff62e989874;hb=899839b9f87a46b49bb3f0eccb9133a8b07c1be7;hp=bdea8ed057828a74dcd6cfae0c6e76d58679c2ae;hpb=ef216ca3d7ddc00c629fbbc37dd1e7f98f9e9220;p=elogind.git
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index bdea8ed05..2b24ff8a9 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -19,6 +19,7 @@
along with systemd; If not, see .
***/
+#include
#include
#include
#include
@@ -33,6 +34,8 @@
#include "log.h"
#include "path-util.h"
#include "pager.h"
+#include "macro.h"
+#include "journal-internal.h"
static enum {
ACTION_NONE,
@@ -41,7 +44,6 @@ static enum {
ACTION_GDB,
} arg_action = ACTION_LIST;
-static Set *matches = NULL;
static FILE* output = NULL;
static char* field = NULL;
@@ -66,10 +68,9 @@ static Set *new_matches(void) {
return NULL;
}
- r = set_put(set, tmp);
+ r = set_consume(set, tmp);
if (r < 0) {
log_error("failed to add to set: %s", strerror(-r));
- free(tmp);
set_free(set);
return NULL;
}
@@ -83,6 +84,7 @@ static int help(void) {
"Flags:\n"
" -o --output=FILE Write output to FILE\n"
" --no-pager Do not pipe output into a pager\n"
+ " --no-legend Do not print the column headers.\n\n"
"Commands:\n"
" -h --help Show this help\n"
@@ -102,7 +104,7 @@ static int add_match(Set *set, const char *match) {
unsigned pid;
const char* prefix;
char *pattern = NULL;
- char _cleanup_free_ *p = NULL;
+ _cleanup_free_ char *p = NULL;
if (strchr(match, '='))
prefix = "";
@@ -123,22 +125,21 @@ static int add_match(Set *set, const char *match) {
if (!pattern)
goto fail;
- r = set_put(set, pattern);
+ log_debug("Adding pattern: %s", pattern);
+ r = set_consume(set, pattern);
if (r < 0) {
- log_error("failed to add pattern '%s': %s",
+ log_error("Failed to add pattern '%s': %s",
pattern, strerror(-r));
goto fail;
}
- log_debug("Added pattern: %s", pattern);
return 0;
fail:
- free(pattern);
- log_error("failed to add match: %s", strerror(-r));
+ log_error("Failed to add match: %s", strerror(-r));
return r;
}
-static int parse_argv(int argc, char *argv[]) {
+static int parse_argv(int argc, char *argv[], Set *matches) {
enum {
ARG_VERSION = 0x100,
ARG_NO_PAGER,
@@ -154,7 +155,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "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);
@@ -162,16 +163,15 @@ static int parse_argv(int argc, char *argv[]) {
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(DISTRIBUTION);
puts(SYSTEMD_FEATURES);
- arg_action = ACTION_NONE;
return 0;
case ARG_NO_PAGER:
@@ -209,13 +209,12 @@ static int parse_argv(int argc, char *argv[]) {
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;
@@ -261,14 +260,14 @@ static int retrieve(const void *data,
return 0;
*var = strndup((const char*)data + ident, len - ident);
- if (!var)
+ if (!*var)
return log_oom();
return 0;
}
static void print_field(FILE* file, sd_journal *j) {
- const char _cleanup_free_ *value = NULL;
+ _cleanup_free_ const char *value = NULL;
const void *d;
size_t l;
@@ -281,7 +280,7 @@ static void print_field(FILE* file, sd_journal *j) {
}
static int print_entry(FILE* file, sd_journal *j, int had_legend) {
- const char _cleanup_free_
+ _cleanup_free_ const char
*pid = NULL, *uid = NULL, *gid = NULL,
*sgnl = NULL, *exe = NULL;
const void *d;
@@ -341,6 +340,11 @@ 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
+ * pick a fairly low data threshold here */
+ sd_journal_set_data_threshold(j, 4096);
+
SD_JOURNAL_FOREACH(j) {
if (field)
print_field(stdout, j);
@@ -380,6 +384,9 @@ static int dump_core(sd_journal* j) {
assert(j);
+ /* We want full data, nothing truncated. */
+ sd_journal_set_data_threshold(j, 0);
+
r = focus(j);
if (r < 0)
return r;
@@ -427,6 +434,8 @@ static int run_gdb(sd_journal *j) {
assert(j);
+ sd_journal_set_data_threshold(j, 0);
+
r = focus(j);
if (r < 0)
return r;
@@ -470,7 +479,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;
}
@@ -509,11 +518,13 @@ finish:
}
int main(int argc, char *argv[]) {
- sd_journal *j = NULL;
+ _cleanup_journal_close_ sd_journal*j = NULL;
const char* match;
Iterator it;
int r = 0;
+ _cleanup_set_free_free_ Set *matches = NULL;
+ setlocale(LC_ALL, "");
log_parse_environment();
log_open();
@@ -523,7 +534,7 @@ int main(int argc, char *argv[]) {
goto end;
}
- r = parse_argv(argc, argv);
+ r = parse_argv(argc, argv, matches);
if (r < 0)
goto end;
@@ -545,11 +556,18 @@ 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:
if (!arg_no_pager)
- pager_open();
+ pager_open(false);
r = dump_list(j);
break;
@@ -567,11 +585,6 @@ int main(int argc, char *argv[]) {
}
end:
- if (j)
- sd_journal_close(j);
-
- set_free_free(matches);
-
pager_close();
if (output)