Skip to content

Commit

Permalink
Ensure signal is forwarded to virt-launcher process
Browse files Browse the repository at this point in the history
Signed-off-by: David Vossel <[email protected]>
  • Loading branch information
davidvossel committed Apr 10, 2018
1 parent b3fe6cb commit 2ca42cd
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions cmd/virt-launcher/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/bin/bash
set +e

_term() {
echo "caught signal"
kill -TERM "$virt_launcher_pid" 2>/dev/null
}

trap _term SIGTERM SIGINT SIGQUIT

# HACK
# Try to create /dev/kvm if not present
if [ ! -e /dev/kvm ]; then
Expand All @@ -10,13 +17,24 @@ fi
chown :qemu /dev/kvm
chmod 660 /dev/kvm


# Cockpit/OCP hack to all shoing the vm terminal
mv /usr/bin/sh /usr/bin/sh.orig
mv /sh.sh /usr/bin/sh
chmod +x /usr/bin/sh

./virt-launcher $@
./virt-launcher $@ &
virt_launcher_pid=$!
while true; do
if ! [ -d /proc/$virt_launcher_pid ]; then
break;
fi
sleep 1
done
# call wait after we know the pid has exited in order
# to get the return code. If we call wait before the pid
# exits, wait will actually return early when we forward
# the trapped signal in _trap(). We don't want that.
wait -n $virt_launcher_pid
rc=$?

echo "virt-launcher exited with code $rc"
Expand Down

0 comments on commit 2ca42cd

Please sign in to comment.