diff options
Diffstat (limited to 'arch/s390/self-hosted-builder/fs/usr/bin/entrypoint')
-rwxr-xr-x | arch/s390/self-hosted-builder/fs/usr/bin/entrypoint | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/arch/s390/self-hosted-builder/fs/usr/bin/entrypoint b/arch/s390/self-hosted-builder/fs/usr/bin/entrypoint new file mode 100755 index 0000000..eb8772b --- /dev/null +++ b/arch/s390/self-hosted-builder/fs/usr/bin/entrypoint @@ -0,0 +1,30 @@ +#!/bin/bash + +# +# Container entrypoint that waits for all spawned processes. +# + +set -e -u + +# Create a FIFO and start reading from its read end. +tempdir=$(mktemp -d "/tmp/done.XXXXXXXXXX") +trap 'rm -r "$tempdir"' EXIT +done="$tempdir/pipe" +mkfifo "$done" +cat "$done" & waiter=$! + +# Start the workload. Its descendants will inherit the FIFO's write end. +status=0 +if [ "$#" -eq 0 ]; then + bash 9>"$done" || status=$? +else + "$@" 9>"$done" || status=$? +fi + +# When the workload and all of its descendants exit, the FIFO's write end will +# be closed and `cat "$done"` will exit. Wait until it happens. This is needed +# in order to handle SelfUpdater, which the workload may start in background +# before exiting. +wait "$waiter" + +exit "$status" |