From: Yu Watanabe Date: Fri, 17 Oct 2025 08:25:23 +0000 (+0900) Subject: coredump-context: cache if the crashed process in the same PID namespace X-Git-Tag: v259-rc1~190^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91840f324e581be1aac77c457a19d0e77855a4ba;p=thirdparty%2Fsystemd.git coredump-context: cache if the crashed process in the same PID namespace --- diff --git a/src/coredump/coredump-context.c b/src/coredump/coredump-context.c index db5dd2e1416..3b13289e429 100644 --- a/src/coredump/coredump-context.c +++ b/src/coredump/coredump-context.c @@ -315,6 +315,19 @@ int coredump_context_build_iovw(CoredumpContext *context) { return 0; } +static void coredump_context_check_pidns(CoredumpContext *context) { + int r; + + assert(context); + assert(pidref_is_set(&context->pidref)); + + r = pidref_in_same_namespace(/* pid1 = */ NULL, &context->pidref, NAMESPACE_PID); + if (r < 0) + log_debug_errno(r, "Failed to check pidns of crashing process, ignoring: %m"); + + context->same_pidns = r != 0; +} + static int coredump_context_parse_from_procfs(CoredumpContext *context) { int r; @@ -531,6 +544,7 @@ int coredump_context_parse_iovw(CoredumpContext *context) { "Mandatory argument %s not received on socket.", metadata_field_to_string(i)); + coredump_context_check_pidns(context); return 0; } @@ -556,5 +570,6 @@ int coredump_context_parse_from_argv(CoredumpContext *context, int argc, char ** return r; } + coredump_context_check_pidns(context); return coredump_context_parse_from_procfs(context); } diff --git a/src/coredump/coredump-context.h b/src/coredump/coredump-context.h index 32557348f92..f2d44c141c6 100644 --- a/src/coredump/coredump-context.h +++ b/src/coredump/coredump-context.h @@ -59,6 +59,7 @@ struct CoredumpContext { char *auxv; /* META_PROC_AUXV */ size_t auxv_size; /* META_PROC_AUXV */ bool got_pidfd; /* META_ARGV_PIDFD */ + bool same_pidns; bool forwarded; int input_fd; int mount_tree_fd; diff --git a/src/coredump/coredump-kernel-helper.c b/src/coredump/coredump-kernel-helper.c index 8b75382aba0..be3b756a231 100644 --- a/src/coredump/coredump-kernel-helper.c +++ b/src/coredump/coredump-kernel-helper.c @@ -10,7 +10,6 @@ #include "format-util.h" #include "iovec-wrapper.h" #include "log.h" -#include "namespace-util.h" #include "signal-util.h" int coredump_kernel_helper(int argc, char *argv[]) { @@ -50,10 +49,7 @@ int coredump_kernel_helper(int argc, char *argv[]) { context.pidref.pid, context.comm, context.uid, context.signo, signal_to_string(context.signo)); - r = pidref_in_same_namespace(/* pid1 = */ NULL, &context.pidref, NAMESPACE_PID); - if (r < 0) - log_debug_errno(r, "Failed to check pidns of crashing process, ignoring: %m"); - if (r == 0) { + if (!context.same_pidns) { /* If this fails, fallback to the old behavior so that * there is still some record of the crash. */ r = coredump_send_to_container(&context);