[systemd-devel] [PATCH] Set PR_SET_CHILD_REAPER for MANAGER_USER

Auke Kok auke-jan.h.kok at intel.com
Tue Jul 24 13:54:31 PDT 2012


Become the reaper for all children part of the user session.

Tested with several forking services.

Keep a local #define for the prctl value around because not many
will have updated kernel-headers for a while - Add TODO entry
to mark a good point in time to remove it.
---
 TODO            |  2 ++
 src/core/main.c | 13 +++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/TODO b/TODO
index 2d25243..3f2d77d 100644
--- a/TODO
+++ b/TODO
@@ -454,3 +454,5 @@ Scheduled for removal (or fixing):
 * journald.conf: ImportKernel=
 
 * prefdm.service
+
+* #ifndef PR_SET_CHILD_SUBREAPER define in src/core/main.c, after kernel 3.8 or so
diff --git a/src/core/main.c b/src/core/main.c
index c7a7a87..7db6e43 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1500,6 +1500,19 @@ int main(int argc, char *argv[]) {
                 }
         }
 
+/* Remove these when kernel-headers are updated in most distro's to 3.4+ */
+#ifndef PR_SET_CHILD_SUBREAPER
+#define PR_SET_CHILD_SUBREAPER 36
+#endif
+        if (arg_running_as == MANAGER_USER) {
+                /* Become reaper of our children */
+                r = prctl(PR_SET_CHILD_SUBREAPER, 1);
+                if (r)
+                        log_error("Failed to prctl(PR_SET_CHILD_SUBREAPER): %s", strerror(-r));
+                if (r == -EINVAL)
+                        log_error("Perhaps the kernel version is too old (< 3.4?)");
+        }
+
         r = manager_new(arg_running_as, &m);
         if (r < 0) {
                 log_error("Failed to allocate manager object: %s", strerror(-r));
-- 
1.7.11.2



More information about the systemd-devel mailing list