From: Yu Watanabe Date: Thu, 21 Mar 2024 20:14:33 +0000 (+0900) Subject: coredumpctl: use journal_add_match_pair() X-Git-Tag: v256-rc1~412^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5cacb0b6455ce8c83fce11269b162d06f6c5a342;p=thirdparty%2Fsystemd.git coredumpctl: use journal_add_match_pair() Also, - use is_path(), - drop unused pid. --- diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c index 52ded50776c..8ff9e34bdd3 100644 --- a/src/coredump/coredumpctl.c +++ b/src/coredump/coredumpctl.c @@ -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; }