coredumpctl: use journal_add_match_pair()

Also,
- use is_path(),
- drop unused pid.
This commit is contained in:
Yu Watanabe
2024-03-25 21:39:34 +09:00
parent e21ad9c136
commit 5cacb0b645
+14 -12
View File
@@ -74,29 +74,31 @@ STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep);
static int add_match(sd_journal *j, const char *match) {
_cleanup_free_ char *p = NULL;
const char* prefix, *pattern;
pid_t pid;
const char *field;
int r;
if (strchr(match, '='))
prefix = "";
else if (strchr(match, '/')) {
field = NULL;
else if (is_path(match)) {
r = path_make_absolute_cwd(match, &p);
if (r < 0)
return log_error_errno(r, "path_make_absolute_cwd(\"%s\"): %m", match);
match = p;
prefix = "COREDUMP_EXE=";
} else if (parse_pid(match, &pid) >= 0)
prefix = "COREDUMP_PID=";
field = "COREDUMP_EXE";
} else if (parse_pid(match, NULL) >= 0)
field = "COREDUMP_PID";
else
prefix = "COREDUMP_COMM=";
field = "COREDUMP_COMM";
pattern = strjoina(prefix, match);
log_debug("Adding match: %s", pattern);
r = sd_journal_add_match(j, pattern, 0);
log_debug("Adding match: %s%s%s", strempty(field), field ? "=" : "", match);
if (field)
r = journal_add_match_pair(j, field, match);
else
r = sd_journal_add_match(j, match, 0);
if (r < 0)
return log_error_errno(r, "Failed to add match \"%s\": %m", match);
return log_error_errno(r, "Failed to add match \"%s%s%s\": %m",
strempty(field), field ? "=" : "", match);
return 0;
}