1#!/bin/bash 2 3# 4# Container entrypoint that waits for all spawned processes. 5# 6 7set -e -u 8 9# /dev/kvm has host permissions, fix it. 10if [ -e /dev/kvm ]; then 11 sudo chown root:kvm /dev/kvm 12fi 13 14# Create a FIFO and start reading from its read end. 15tempdir=$(mktemp -d "/tmp/done.XXXXXXXXXX") 16trap 'rm -r "$tempdir"' EXIT 17done="$tempdir/pipe" 18mkfifo "$done" 19cat "$done" & waiter=$! 20 21# Start the workload. Its descendants will inherit the FIFO's write end. 22status=0 23if [ "$#" -eq 0 ]; then 24 bash 9>"$done" || status=$? 25else 26 "$@" 9>"$done" || status=$? 27fi 28 29# When the workload and all of its descendants exit, the FIFO's write end will 30# be closed and `cat "$done"` will exit. Wait until it happens. This is needed 31# in order to handle SelfUpdater, which the workload may start in background 32# before exiting. 33wait "$waiter" 34 35exit "$status" 36