aboutsummaryrefslogtreecommitdiffstats
path: root/test/scripts/setsid_wrapper.sh
blob: 030c3b079de730b6ef1efcdd227b868ba7a248c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/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