Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an environment variable flag for -g #101

Merged
merged 1 commit into from
Apr 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/tini.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static int32_t expect_status[(STATUS_MAX - STATUS_MIN + 1) / 32];
#endif

#define VERBOSITY_ENV_VAR "TINI_VERBOSITY"
#define KILL_PROCESS_GROUP_GROUP_ENV_VAR "TINI_KILL_PROCESS_GROUP"

#define TINI_VERSION_STRING "tini version " TINI_VERSION TINI_GIT

Expand Down Expand Up @@ -254,9 +255,10 @@ void print_usage(char* const name, FILE* const file) {

fprintf(file, "Environment variables:\n\n");
#if HAS_SUBREAPER
fprintf(file, " %s: Register as a process subreaper (requires Linux >= 3.4)\n", SUBREAPER_ENV_VAR);
fprintf(file, " %s: Register as a process subreaper (requires Linux >= 3.4).\n", SUBREAPER_ENV_VAR);
#endif
fprintf(file, " %s: Set the verbosity level (default: %d)\n", VERBOSITY_ENV_VAR, DEFAULT_VERBOSITY);
fprintf(file, " %s: Set the verbosity level (default: %d).\n", VERBOSITY_ENV_VAR, DEFAULT_VERBOSITY);
fprintf(file, " %s: Send signals to the child's process group.\n", KILL_PROCESS_GROUP_GROUP_ENV_VAR);

fprintf(file, "\n");
}
Expand Down Expand Up @@ -397,6 +399,10 @@ int parse_env() {
}
#endif

if (getenv(KILL_PROCESS_GROUP_GROUP_ENV_VAR) != NULL) {
kill_process_group++;
}

char* env_verbosity = getenv(VERBOSITY_ENV_VAR);
if (env_verbosity != NULL) {
verbosity = atoi(env_verbosity);
Expand Down
13 changes: 12 additions & 1 deletion test/run_inner_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,24 @@ def main():
# This test has Tini spawn a process that ignores SIGUSR1 and spawns a child that doesn't (and waits on the child)
# We send SIGUSR1 to Tini, and expect the grand-child to terminate, then the child, and then Tini.
if not args_disabled:
print "Running process group test"
print "Running process group test (arguments)"
p = subprocess.Popen([tini, '-g', os.path.join(src, "test", "pgroup", "stage_1.py")], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

busy_wait(lambda: len(psutil.Process(p.pid).children(recursive=True)) == 2, 10)
p.send_signal(signal.SIGUSR1)
busy_wait(lambda: p.poll() is not None, 10)

print "Running process group test (environment variable)"
p = subprocess.Popen(
[tini, os.path.join(src, "test", "pgroup", "stage_1.py")],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=dict(os.environ, TINI_KILL_PROCESS_GROUP="1")
)

busy_wait(lambda: len(psutil.Process(p.pid).children(recursive=True)) == 2, 10)
p.send_signal(signal.SIGUSR1)
busy_wait(lambda: p.poll() is not None, 10)

# Run failing test. Force verbosity to 1 so we see the subreaper warning
# regardless of whether MINIMAL is set.
print "Running zombie reaping failure test (Tini should warn)"
Expand Down