From dc49da32b739aac23af4fe99f0250d0f9d3379d5 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Mon, 3 Jul 2017 01:12:33 +0100 Subject: [PATCH] (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). --- src/dinit.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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. -- 2.25.1