| 1 |
#! /usr/bin/env bash |
| 2 |
# |
| 3 |
# Usage: btest-bg-run <tag> <cmdline> |
| 4 |
# |
| 5 |
# Creates a new empty working directory <tag> within the current directory |
| 6 |
# and spawns <cmdline> in there in the background. It also records |
| 7 |
# a set of meta information that btest-bg-wait will read. |
| 8 |
|
| 9 |
if [ "$#" -le 1 ]; then |
| 10 |
echo "usage: $(basename "$0") <tag> <cmdline>" |
| 11 |
exit 1 |
| 12 |
fi |
| 13 |
|
| 14 |
cwd=$(pwd) |
| 15 |
cd "$(dirname "$0")" || exit 1 |
| 16 |
helper=$(pwd)/btest-bg-run-helper |
| 17 |
setsid=$(pwd)/btest-setsid |
| 18 |
cd "$cwd" || exit 1 |
| 19 |
|
| 20 |
dir=$1 |
| 21 |
shift |
| 22 |
|
| 23 |
if [ -e "$dir" ]; then |
| 24 |
echo "directory '$dir' already exists" >&2 |
| 25 |
exit 1 |
| 26 |
fi |
| 27 |
|
| 28 |
echo "$dir" >>.bgprocs |
| 29 |
mkdir "$dir" |
| 30 |
cd "$dir" || exit 1 |
| 31 |
|
| 32 |
echo "$@" >.cmdline |
| 33 |
|
| 34 |
$setsid "$helper" "$@" >.stdout 2>.stderr & |
| 35 |
|
| 36 |
sleep 1 |