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