Skip to content

Commit fe4b2f0

Browse files
committed
Add an environment variable flag for -g
Fixes: #100
1 parent e972ea5 commit fe4b2f0

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/tini.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static int32_t expect_status[(STATUS_MAX - STATUS_MIN + 1) / 32];
9898
#endif
9999

100100
#define VERBOSITY_ENV_VAR "TINI_VERBOSITY"
101+
#define KILL_PROCESS_GROUP_GROUP_ENV_VAR "TINI_KILL_PROCESS_GROUP"
101102

102103
#define TINI_VERSION_STRING "tini version " TINI_VERSION TINI_GIT
103104

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

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

261263
fprintf(file, "\n");
262264
}
@@ -397,6 +399,10 @@ int parse_env() {
397399
}
398400
#endif
399401

402+
if (getenv(KILL_PROCESS_GROUP_GROUP_ENV_VAR) != NULL) {
403+
kill_process_group++;
404+
}
405+
400406
char* env_verbosity = getenv(VERBOSITY_ENV_VAR);
401407
if (env_verbosity != NULL) {
402408
verbosity = atoi(env_verbosity);

test/run_inner_tests.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,24 @@ def main():
113113
# This test has Tini spawn a process that ignores SIGUSR1 and spawns a child that doesn't (and waits on the child)
114114
# We send SIGUSR1 to Tini, and expect the grand-child to terminate, then the child, and then Tini.
115115
if not args_disabled:
116-
print "Running process group test"
116+
print "Running process group test (arguments)"
117117
p = subprocess.Popen([tini, '-g', os.path.join(src, "test", "pgroup", "stage_1.py")], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
118118

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

123+
print "Running process group test (environment variable)"
124+
p = subprocess.Popen(
125+
[tini, os.path.join(src, "test", "pgroup", "stage_1.py")],
126+
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
127+
env=dict(os.environ, TINI_KILL_PROCESS_GROUP="1")
128+
)
129+
130+
busy_wait(lambda: len(psutil.Process(p.pid).children(recursive=True)) == 2, 10)
131+
p.send_signal(signal.SIGUSR1)
132+
busy_wait(lambda: p.poll() is not None, 10)
133+
123134
# Run failing test. Force verbosity to 1 so we see the subreaper warning
124135
# regardless of whether MINIMAL is set.
125136
print "Running zombie reaping failure test (Tini should warn)"

0 commit comments

Comments
 (0)