mirror of https://github.com/krallin/tini.git
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:
parent
1dc66f81eb
commit
e1b463cdf5
18
src/tini.c
18
src/tini.c
|
@ -28,6 +28,7 @@
|
||||||
#ifdef PR_SET_CHILD_SUBREAPER
|
#ifdef PR_SET_CHILD_SUBREAPER
|
||||||
#define HAS_SUBREAPER 1
|
#define HAS_SUBREAPER 1
|
||||||
#define OPT_STRING "hsv"
|
#define OPT_STRING "hsv"
|
||||||
|
#define SUBREAPER_ENV_VAR "TINI_SUBREAPER"
|
||||||
#else
|
#else
|
||||||
#define HAS_SUBREAPER 0
|
#define HAS_SUBREAPER 0
|
||||||
#define OPT_STRING "hv"
|
#define OPT_STRING "hv"
|
||||||
|
@ -128,6 +129,15 @@ int parse_args(const int argc, char* const argv[], char* (**child_args_ptr_ptr)[
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int parse_env() {
|
||||||
|
#if HAS_SUBREAPER
|
||||||
|
if (getenv(SUBREAPER_ENV_VAR) != NULL) {
|
||||||
|
subreaper++;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if HAS_SUBREAPER
|
#if HAS_SUBREAPER
|
||||||
int register_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\
|
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\
|
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;
|
return parse_exitcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Parse environment */
|
||||||
|
if (parse_env()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Prepare sigmask */
|
/* Prepare sigmask */
|
||||||
sigset_t parent_sigset;
|
sigset_t parent_sigset;
|
||||||
sigset_t child_sigset;
|
sigset_t child_sigset;
|
||||||
|
|
Loading…
Reference in New Issue