blob: 550c7b9477891eef1bdadbe3d10843823748a6da [file] [log] [blame]
Tom Jonesc3b416c2024-01-18 14:51:44 +00001#!/usr/bin/env bash
Klement Sekeradb4e84c2017-08-11 10:06:15 +02002
Klement Sekerab23ffd72021-05-31 16:08:53 +02003cmd=$1
4force_foreground=$2
5shift
6shift
7
8if [[ "$force_foreground" == "1" ]]
Klement Sekeradb4e84c2017-08-11 10:06:15 +02009then
Klement Sekerab23ffd72021-05-31 16:08:53 +020010 setsid $cmd $force_foreground $*
Klement Sekeradb4e84c2017-08-11 10:06:15 +020011else
Klement Sekerab23ffd72021-05-31 16:08:53 +020012 setsid $cmd $force_foreground $* &
Klement Sekeradb4e84c2017-08-11 10:06:15 +020013 pid=$!
14 trap "echo setsid_wrapper.sh: got signal, killing child pid ${pid}; kill ${pid}; sleep .1;" SIGINT SIGTERM
Klement Sekera8712ada2017-08-16 16:38:10 +020015 wait ${pid}
16 exit $?
Klement Sekeradb4e84c2017-08-11 10:06:15 +020017fi