Merge branch 'buck/buck-review' into process-groups
This commit is contained in:
commit
427bdd25ba
5 changed files with 25 additions and 45 deletions
|
@ -128,7 +128,7 @@ int main(int argc, char *argv[]) {
|
|||
waitpid(child, &status, 0);
|
||||
exit_status = WEXITSTATUS(status);
|
||||
|
||||
DEBUG("Child exited with status %d, goodbye.\n", exit_status);
|
||||
DEBUG("Child exited with status %d. Goodbye.\n", exit_status);
|
||||
|
||||
return exit_status;
|
||||
}
|
||||
|
|
4
test
4
test
|
@ -18,8 +18,8 @@ run_tests() {
|
|||
./test-help-message "$dumb_init_bin"
|
||||
done
|
||||
|
||||
./test-pgroup "$dumb_init_bin"
|
||||
./test-no-pgroup "$dumb_init_bin"
|
||||
DUMB_INIT_PROCESS_GROUP=0 ./test-pgroup "$dumb_init_bin" 4
|
||||
DUMB_INIT_PROCESS_GROUP=1 ./test-pgroup "$dumb_init_bin" 0
|
||||
}
|
||||
|
||||
cd tests
|
||||
|
|
|
@ -6,15 +6,15 @@ dumb_init="$1"
|
|||
|
||||
status=$($dumb_init > /dev/null 2>&1; echo $?)
|
||||
|
||||
if [ "$status" -ne 0 ]; then
|
||||
msg=$($dumb_init 2>&1 || true)
|
||||
msg_len=${#msg}
|
||||
|
||||
if [ "$msg_len" -le 50 ]; then
|
||||
echo "Error: Expected dumb-init with no arguments to print a useful message, but it was only ${msg_len} chars long."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "Error: Expected dumb-init with no arguments to return nonzero, but it returned ${status}."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
msg=$($dumb_init 2>&1 || true)
|
||||
msg_len=${#msg}
|
||||
|
||||
if [ "$msg_len" -le 50 ]; then
|
||||
echo "Error: Expected dumb-init with no arguments to print a useful message, but it was only ${msg_len} chars long."
|
||||
exit 1
|
||||
fi
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
#!/bin/bash -euxm
|
||||
# dumb-init should not proxy signals to a process group rooted at its child if
|
||||
# asked not to.
|
||||
dumb_init="$1"
|
||||
|
||||
DUMB_INIT_PROCESS_GROUP=0 $dumb_init nohup sh -c "yes 'oh, hi' | tail & yes error | tail >&2" > /dev/null &
|
||||
pid="$!"
|
||||
|
||||
sleep 1
|
||||
shell_pid=$(pgrep -P "$pid")
|
||||
child_pids=$(pgrep -P $shell_pid)
|
||||
|
||||
kill -TERM "$pid"
|
||||
sleep 1
|
||||
|
||||
# ensure all processes are still running
|
||||
while read pid; do
|
||||
if pgrep "$pid"; then
|
||||
echo "Error: expected process $pid to still be alive, but it wasn't."
|
||||
exit 1
|
||||
else
|
||||
echo "Process $pid was still alive (as expected)."
|
||||
fi
|
||||
done <<< "$child_pids"
|
||||
xargs kill -9 <<< "$child_pids"
|
|
@ -2,26 +2,31 @@
|
|||
# dumb-init should proxy signals to a process group rooted at its child when
|
||||
# requested.
|
||||
dumb_init="$1"
|
||||
after_count="$2"
|
||||
|
||||
DUMB_INIT_PROCESS_GROUP=1 $dumb_init nohup sh -c "yes 'oh, hi' | tail & yes error | tail >&2" > /dev/null &
|
||||
$dumb_init sh -c "yes 'oh, hi' | tail & yes error | tail >&2" &
|
||||
pid="$!"
|
||||
|
||||
sleep 1
|
||||
shell_pid=$(pgrep -P "$pid")
|
||||
pstree -p "$pid"
|
||||
pids=$(pstree -p "$pid" | grep -Po '(\d+)' | grep -Po '\d+')
|
||||
|
||||
# ensure processes are running
|
||||
child_count=$(pgrep -g "$shell_pid" | grep -v "$shell_pid" | wc -l) || true
|
||||
child_count=$(ps -o pid= $pids | wc -l) || true
|
||||
|
||||
if [ "$child_count" -ne 4 ]; then
|
||||
echo "Error: Expected 4 children, instead we had ${child_count}."
|
||||
if [ "$child_count" -ne 6 ]; then
|
||||
echo "Error: Expected 6 children, instead we had ${child_count}."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ensure processes are dead after signal
|
||||
kill -TERM "$pid"
|
||||
child_count=$(pgrep -g "$shell_pid" | grep -v "$shell_pid" | wc -l) || true
|
||||
sleep 1
|
||||
child_count=$(ps -o pid= $pids | wc -l) || true
|
||||
|
||||
if [ "$child_count" -ne 0 ]; then
|
||||
echo "Error: Expected 0 children, instead we had ${child_count}."
|
||||
if [ "$child_count" -ne "$after_count" ]; then
|
||||
echo "Error: Expected $after_count children, instead we had ${child_count}."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
xargs kill -9 <<< "$pids"
|
||||
|
|
Loading…
Reference in a new issue