aboutsummaryrefslogtreecommitdiffstats
path: root/test/scripts/setsid_wrapper.sh
blob: 550c7b9477891eef1bdadbe3d10843823748a6da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env bash

cmd=$1
force_foreground=$2
shift
shift

if [[ "$force_foreground" == "1" ]]
then
	setsid $cmd $force_foreground $*
else
	setsid $cmd $force_foreground $* &
	pid=$!
	trap "echo setsid_wrapper.sh: got signal, killing child pid ${pid}; kill ${pid}; sleep .1;" SIGINT SIGTERM
	wait ${pid}
	exit $?
fi