Ensure signal is forwarded to virt-launcher process
#!/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
@@ -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"
