dumb-init/tests/test-proxies-signals
2015-08-07 16:04:30 -07:00

43 lines
1 KiB
Bash
Executable file

#!/bin/sh -eum
# dumb-init should proxy all possible signals to the child process.
dumb_init="$1"
# Try sending all signals via dumb-init to our `print-signals` script, ensure
# they were all received.
. ./lib/testlib.sh
# The easiest way to communicate with the background process is with a FIFO.
# (piping spawns additional subshells and makes it hard to get the right PID)
fifo=$(mktemp -u)
mkfifo -m 600 "$fifo"
read_cmd="timeout 1 head -n1 $fifo"
$dumb_init ./lib/print-signals "$fifo" &
pid="$!"
# Wait for `print-signals` to indicate it's ready.
$read_cmd > /dev/null
for expected in $(catchable_signals); do
kill -s "$expected" "$pid"
echo -n "Sent signal ${expected}... "
received=$($read_cmd) || {
echo
echo "Error: Didn't receive signal within 1 second."
exit 1
}
echo "received signal ${received}."
if [ "$expected" -ne "$received" ]; then
echo "Error: Received signal $received, but expected signal $expected."
exit 1
fi
done
# Turn off job monitoring so we don't get a spurious "[1] + Killed" printed
set +m
kill -9 "$pid"
rm "$fifo"