From: Davin McCall Date: Mon, 3 Jul 2017 00:12:33 +0000 (+0100) Subject: (Linux) set dinit as child subreaper. X-Git-Tag: v0.06~28 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=dc49da32b739aac23af4fe99f0250d0f9d3379d5;p=oweals%2Fdinit.git (Linux) set dinit as child subreaper. This allows catching/watching double-forking processes even if we are not PID 1. Double-fork orphans will be reparented to the subreaper (i.e. Dinit) rather than PID 1 (init). --- diff --git a/src/dinit.cc b/src/dinit.cc index ffbae7d..460bef0 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -12,6 +12,9 @@ #include #include #include +#ifdef __linux__ +#include +#endif #include "dasynq.h" #include "service.h" @@ -219,7 +222,11 @@ int dinit_main(int argc, char **argv) if (onefd > 2) close(onefd); 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; @@ -229,7 +236,7 @@ int dinit_main(int argc, char **argv) sigaddset(&sigwait_set, SIGTERM); if (am_system_init) sigaddset(&sigwait_set, SIGQUIT); sigprocmask(SIG_BLOCK, &sigwait_set, NULL); - + // Terminal access control signals - we block these so that dinit can't be // suspended if it writes to the terminal after some other process has claimed // ownership of it.