diff --git a/dumb-init.c b/dumb-init.c index 07f5525..6c50baa 100644 --- a/dumb-init.c +++ b/dumb-init.c @@ -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; } diff --git a/test b/test index ce6785a..46c2513 100755 --- a/test +++ b/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 diff --git a/tests/test-help-message b/tests/test-help-message index b1c45a1..76d9424 100755 --- a/tests/test-help-message +++ b/tests/test-help-message @@ -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 diff --git a/tests/test-no-pgroup b/tests/test-no-pgroup deleted file mode 100755 index 8a2d4dd..0000000 --- a/tests/test-no-pgroup +++ /dev/null @@ -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" diff --git a/tests/test-pgroup b/tests/test-pgroup index d6bfccb..e80e14d 100755 --- a/tests/test-pgroup +++ b/tests/test-pgroup @@ -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"