coredump: do not try to read si_code more than once

This also renames coredump_context_read_pidfd_info() to
coredump_context_read_code(), as it only reads COREDUMP_CODE.

This does not change anything effectively, as the function is called
only once. Preparation for later change.
This commit is contained in:
Yu Watanabe
2026-08-27 05:50:14 +09:00
parent d81e6b93d6
commit 3fd564e876
2 changed files with 14 additions and 9 deletions
+12 -8
View File
@@ -181,7 +181,7 @@ static int get_process_container_parent_cmdline(PidRef *pid, char** ret_cmdline)
/* The kernel passes si_signo through core_pattern (%s). Starting with v7.1,
* si_code is reported as well via pidfd. */
static int coredump_context_read_pidfd_info(CoredumpContext *context) {
static int coredump_context_read_code(CoredumpContext *context) {
struct pidfd_info info = {
.mask = PIDFD_INFO_COREDUMP,
};
@@ -190,19 +190,23 @@ static int coredump_context_read_pidfd_info(CoredumpContext *context) {
assert(context);
assert(pidref_is_set(&context->pidref));
if (!context->got_pidfd || context->pidref.fd < 0)
if (!context->got_pidfd || context->pidref.fd < 0 || context->got_code >= 0)
return 0;
r = pidfd_get_info(context->pidref.fd, &info);
if (ERRNO_IS_NEG_NOT_SUPPORTED(r))
return log_debug_errno(r, "PIDFD_INFO_COREDUMP not supported, ignoring: %m");
if (r < 0)
if (r < 0) {
context->got_code = false;
if (ERRNO_IS_NEG_NOT_SUPPORTED(r))
return log_debug_errno(r, "PIDFD_INFO_COREDUMP not supported, ignoring: %m");
return log_debug_errno(r, "Failed to get pidfd coredump info, ignoring: %m");
}
if (FLAGS_SET(info.mask, PIDFD_INFO_COREDUMP_CODE)) {
context->code = (int) info.coredump_code;
context->got_code = true;
}
} else
context->got_code = false;
return 0;
}
@@ -246,7 +250,7 @@ int coredump_context_build_iovw(CoredumpContext *context) {
(void) iovw_put_string_field(&context->iovw, "COREDUMP_SIGNAL_NAME=SIG", signal_to_string(context->signo));
/* Emit si_code if we learned it from pidfd_info */
if (context->got_code)
if (context->got_code > 0)
(void) iovw_put_string_fieldf(&context->iovw, "COREDUMP_CODE=", "%i", context->code);
}
@@ -402,7 +406,7 @@ static int coredump_context_parse_from_procfs(CoredumpContext *context) {
if (r < 0)
log_warning_errno(r, "Failed to get auxv, ignoring: %m");
(void) coredump_context_read_pidfd_info(context);
(void) coredump_context_read_code(context);
r = pidref_verify(&context->pidref);
if (r < 0)
+2 -1
View File
@@ -65,7 +65,7 @@ struct CoredumpContext {
size_t auxv_size; /* META_PROC_AUXV */
char *thread_name; /* META_THREAD_NAME */
bool got_pidfd; /* META_ARGV_PIDFD */
bool got_code; /* META_CODE */
int got_code; /* META_CODE, tristate */
bool same_pidns;
bool forwarded;
int input_fd;
@@ -79,6 +79,7 @@ struct CoredumpContext {
.uid = UID_INVALID, \
.gid = GID_INVALID, \
.tidref = PIDREF_NULL, \
.got_code = -1, \
.mount_tree_fd = -EBADF, \
.input_fd = -EBADF, \
}