Stéphane Graber has proposed merging lp:~stgraber/upstart/upstart-prctl into
lp:upstart.
Requested reviews:
Upstart Reviewers (upstart-reviewers)
For more details, see:
https://code.launchpad.net/~stgraber/upstart/upstart-prctl/+merge/136759
Add a call to prctl to set the init process as the subreaper.
This basically prevents any child process to double fork and get re-parented
to PID 1. Any process attempting a double fork will simply be re-parented to
the closest init process in the process tree.
This feature allows Session Inits to track the state of their children and
receive SIGCHLD for them when they die.
The PR_SET_CHILD_SUBREAPER flag was added in the 3.4 kernel.
In the event where the kernel doesn't support it, upstart will emit a
prctl-subreaper-failed event as well as log a warning message.
On such system, tracking child process status won't be reliable and once we
have the user jobs implemented, the respawn statement for those should be
ignored when we can't setuup the subreaper as to avoid tracking problems,
potentially leading to loops.
--
https://code.launchpad.net/~stgraber/upstart/upstart-prctl/+merge/136759
Your team Upstart Reviewers is requested to review the proposed merge of
lp:~stgraber/upstart/upstart-prctl into lp:upstart.
=== modified file 'init/main.c'
--- init/main.c 2012-11-07 15:17:58 +0000
+++ init/main.c 2012-11-28 18:57:36 +0000
@@ -29,6 +29,7 @@
#include <sys/reboot.h>
#include <sys/resource.h>
#include <sys/mount.h>
+#include <sys/prctl.h>
#include <errno.h>
#include <stdio.h>
@@ -603,6 +604,18 @@
if (disable_sessions)
nih_debug ("Sessions disabled");
+ /* Set us as the child subreaper.
+ * This ensures that even when init doesn't run as PID 1, it'll always be
+ * the ultimate parent of everything it spawns. */
+
+ if (getpid () > 1 && prctl (PR_SET_CHILD_SUBREAPER, 1) < 0) {
+ nih_warn ("%s: %s", _("Unable to mark us as a subreaper"),
+ strerror (errno));
+
+ // Emit prctl-subreaper-failed event
+ NIH_MUST (event_new (NULL, "prctl-subreaper-failed", NULL));
+ }
+
/* Run through the loop at least once to deal with signals that were
* delivered to the previous process while the mask was set or to
* process the startup event we emitted.
--
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at:
https://lists.ubuntu.com/mailman/listinfo/upstart-devel