summaryrefslogtreecommitdiffstats
path: root/src/basic/process-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-10-16 16:13:16 +0200
committerGitHub <noreply@github.com>2023-10-16 16:13:16 +0200
commitcde8cc946be9183c8381a5d30be0a862abd6b389 (patch)
treeb6f5d178333e3d68f75bef09463fb39b157be916 /src/basic/process-util.c
parentmount-util: use mount beneath to replace previous namespace mount (diff)
parentnspawn: set CoredumpReceive=yes on container's scope when --boot is set (diff)
downloadsystemd-cde8cc946be9183c8381a5d30be0a862abd6b389.tar.xz
systemd-cde8cc946be9183c8381a5d30be0a862abd6b389.zip
Merge pull request #29272 from enr0n/coredump-container
coredump: support forwarding coredumps to containers
Diffstat (limited to 'src/basic/process-util.c')
-rw-r--r--src/basic/process-util.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index d0ffb2d614..ed096900ac 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -319,6 +319,33 @@ int container_get_leader(const char *machine, pid_t *pid) {
return 0;
}
+int namespace_get_leader(pid_t pid, NamespaceType type, pid_t *ret) {
+ int r;
+
+ assert(ret);
+
+ for (;;) {
+ pid_t ppid;
+
+ r = get_process_ppid(pid, &ppid);
+ if (r < 0)
+ return r;
+
+ r = in_same_namespace(pid, ppid, type);
+ if (r < 0)
+ return r;
+ if (r == 0) {
+ /* If the parent and the child are not in the same
+ * namespace, then the child is the leader we are
+ * looking for. */
+ *ret = pid;
+ return 0;
+ }
+
+ pid = ppid;
+ }
+}
+
int is_kernel_thread(pid_t pid) {
_cleanup_free_ char *line = NULL;
unsigned long long flags;