From 89876c9580bb85e1e9ad05a2d3e742e71b7fbff3 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Tue, 4 Jul 2017 19:07:37 +0100 Subject: [PATCH] Consolidate linux-specific code. --- src/dinit.cc | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/dinit.cc b/src/dinit.cc index fa804eb..ae859e0 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -14,6 +14,8 @@ #include #ifdef __linux__ #include +#include +#include #endif #include "dasynq.h" @@ -22,11 +24,6 @@ #include "dinit-log.h" #include "dinit-socket.h" -#ifdef __linux__ -#include -#include -#endif - /* * When running as the system init process, Dinit processes the following signals: * @@ -40,7 +37,6 @@ * services even if the halt/reboot commands are unavailable for some reason. */ - using namespace dasynq; using eventloop_t = event_loop; @@ -223,10 +219,6 @@ int dinit_main(int argc, char **argv) if (twofd > 2) close(twofd); } -#ifdef __linux__ - prctl(PR_SET_CHILD_SUBREAPER, 1); -#endif - /* Set up signal handlers etc */ /* SIG_CHILD is ignored by default: good */ sigset_t sigwait_set; @@ -305,6 +297,10 @@ int dinit_main(int argc, char **argv) // Make ctrl+alt+del combination send SIGINT to PID 1 (this process) reboot(RB_DISABLE_CAD); } + + // Mark ourselves as a subreaper. This means that if a process we start double-forks, the + // orphaned child will re-parent to us rather than to PID 1 (although that could be us too). + prctl(PR_SET_CHILD_SUBREAPER, 1); #endif /* start requested services */ -- 2.25.1