Allow subreaping to be controlled with an env var

This allows users to enable subreaping even if they aren't the ones
calling Tini.
This commit is contained in:
Thomas Orozco 2015-09-01 21:15:06 +02:00
parent 1dc66f81eb
commit e1b463cdf5
1 changed files with 17 additions and 1 deletions

View File

@ -28,6 +28,7 @@
#ifdef PR_SET_CHILD_SUBREAPER
#define HAS_SUBREAPER 1
#define OPT_STRING "hsv"
#define SUBREAPER_ENV_VAR "TINI_SUBREAPER"
#else
#define HAS_SUBREAPER 0
#define OPT_STRING "hv"
@ -128,6 +129,15 @@ int parse_args(const int argc, char* const argv[], char* (**child_args_ptr_ptr)[
return 0;
}
int parse_env() {
#if HAS_SUBREAPER
if (getenv(SUBREAPER_ENV_VAR) != NULL) {
subreaper++;
}
#endif
return 0;
}
#if HAS_SUBREAPER
int register_subreaper () {
@ -168,7 +178,8 @@ void reaper_check () {
PRINT_WARNING("Tini is not running as PID 1 and isn't registered as a child subreaper.\n\
Zombie processes will not be re-parented to Tini, so zombie reaping won't work.\n\
Use -s or run Tini as PID 1 to fix the problem.");
To fix the problem, use -s or set the environment variable " SUBREAPER_ENV_VAR " to register Tini as a child subreaper,\n\
or run Tini as PID 1.");
}
@ -305,6 +316,11 @@ int main(int argc, char *argv[]) {
return parse_exitcode;
}
/* Parse environment */
if (parse_env()) {
return 1;
}
/* Prepare sigmask */
sigset_t parent_sigset;
sigset_t child_sigset;