summaryrefslogtreecommitdiff
path: root/src/journal/coredumpctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/journal/coredumpctl.c')
-rw-r--r--src/journal/coredumpctl.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index b6e558186d..5652c2f91a 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -34,6 +34,8 @@
#include "log.h"
#include "path-util.h"
#include "pager.h"
+#include "macro.h"
+#include "journal-internal.h"
static enum {
ACTION_NONE,
@@ -42,7 +44,6 @@ static enum {
ACTION_GDB,
} arg_action = ACTION_LIST;
-static Set *matches = NULL;
static FILE* output = NULL;
static char* field = NULL;
@@ -67,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;
}
@@ -103,7 +103,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 = "";
@@ -124,22 +124,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,
@@ -268,7 +267,7 @@ static int retrieve(const void *data,
}
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;
@@ -519,10 +518,11 @@ 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();
@@ -534,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;
@@ -560,7 +560,7 @@ int main(int argc, char *argv[]) {
case ACTION_LIST:
if (!arg_no_pager)
- pager_open();
+ pager_open(false);
r = dump_list(j);
break;
@@ -578,11 +578,6 @@ int main(int argc, char *argv[]) {
}
end:
- if (j)
- sd_journal_close(j);
-
- set_free_free(matches);
-
pager_close();
if (output)