]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coredump-context: cache if the crashed process in the same PID namespace
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 17 Oct 2025 08:25:23 +0000 (17:25 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 28 Oct 2025 05:31:41 +0000 (14:31 +0900)
src/coredump/coredump-context.c
src/coredump/coredump-context.h
src/coredump/coredump-kernel-helper.c

index db5dd2e141692082a0f04db94d905a28cc06aac0..3b13289e429620618f7b68d0852837aaf0c8fa13 100644 (file)
@@ -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);
 }
index 32557348f92076291c8a158306c0bf070b5eaa5a..f2d44c141c6237e7f53566befda8b489aa25bb4f 100644 (file)
@@ -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;
index 8b75382aba0ba35bcbe2c682fa2499e409c0461c..be3b756a231033e164e764f3d2d5a4bb034a387d 100644 (file)
@@ -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);