Tom Jones | c3b416c | 2024-01-18 14:51:44 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Klement Sekera | db4e84c | 2017-08-11 10:06:15 +0200 | [diff] [blame] | 2 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 3 | cmd=$1 |
4 | force_foreground=$2 | ||||
5 | shift | ||||
6 | shift | ||||
7 | |||||
8 | if [[ "$force_foreground" == "1" ]] | ||||
Klement Sekera | db4e84c | 2017-08-11 10:06:15 +0200 | [diff] [blame] | 9 | then |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 10 | setsid $cmd $force_foreground $* |
Klement Sekera | db4e84c | 2017-08-11 10:06:15 +0200 | [diff] [blame] | 11 | else |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 12 | setsid $cmd $force_foreground $* & |
Klement Sekera | db4e84c | 2017-08-11 10:06:15 +0200 | [diff] [blame] | 13 | pid=$! |
14 | trap "echo setsid_wrapper.sh: got signal, killing child pid ${pid}; kill ${pid}; sleep .1;" SIGINT SIGTERM | ||||
Klement Sekera | 8712ada | 2017-08-16 16:38:10 +0200 | [diff] [blame] | 15 | wait ${pid} |
16 | exit $? | ||||
Klement Sekera | db4e84c | 2017-08-11 10:06:15 +0200 | [diff] [blame] | 17 | fi |