dumb-init/tests/test-proxies-signals

47 lines
1.4 KiB
Text
Raw Normal View History

2015-08-12 00:31:08 +03:00
#!/bin/bash -euxm
# dumb-init should proxy all possible signals to the child process.
dumb_init="$1"
2015-08-05 20:56:55 +03:00
# Try sending all signals via dumb-init to our `print-signals` script, ensure
# they were all received.
. ./lib/testlib.sh
2015-08-05 20:56:55 +03:00
# 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"
2015-08-05 23:05:40 +03:00
read_cmd="timeout 1 head -n1 $fifo"
$dumb_init ./lib/print-signals "$fifo" &
2015-08-05 20:56:55 +03:00
pid="$!"
# Wait for `print-signals` to indicate it's ready.
2015-08-05 23:05:40 +03:00
$read_cmd > /dev/null
2015-08-05 20:56:55 +03:00
for expected in $(catchable_signals); do
2015-08-10 19:32:56 +03:00
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
2015-08-05 20:56:55 +03:00
done
# Turn off job monitoring so we don't get a spurious "[1] + Killed" printed
set +m
# $pid is the PID of the dumb-init process. Since print-signals ignores all
# signals, we need to `kill -9` it. If we just `kill -9` the dumb-init process,
# `print-signals` will still be running. So we instead kill children of the
# dumb-init process.
pkill -9 -P "$pid"
2015-08-05 20:56:55 +03:00
rm "$fifo"