b48325100b
In run_in_venv_with_cleanup.sh, sed was changed to gsed to allow the script to run properly on FreeBSD because the sed script uses an expression that is specific to the gnu sed. Gnu sed is available to be invoked as gsed on FreeBSD systems, but there is no executable or symlink which allows sed to be run by the name gsed on ubuntu 22.04. Check for the existence of gsed. If it's found, use it. Otherwise, just use sed. Type: fix Fixes: b3c863eae4 Signed-off-by: Matthew Smith <mgsmith@netgate.com> Change-Id: I487197e486f500711aa3e87ec7ba899a53606b40
58 lines
1.1 KiB
Bash
Executable File
58 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
rv=0
|
|
|
|
# Minimalist version of cleanup, used for signal handling.
|
|
# Sends a SIGKILL to the entire process group, including ourselves.
|
|
# Needs just two external commands, making it more
|
|
# robust in case of resource issues.
|
|
panic() {
|
|
echo "$0(pid $$): Caught a signal, emergency clean-up"
|
|
# use "pgid:1=" output format to get unpadded process group ID
|
|
group_id=`ps -p $$ -o pgid:1=`
|
|
echo "$0(pid $$): sending kill to process group ID:${group_id}"
|
|
kill -9 -- -${group_id}
|
|
# not reached
|
|
}
|
|
|
|
# Happy camper leisurely clean up - send the signal only to other
|
|
# processes in the process group, and also check
|
|
# that the processes exists before sending the signal.
|
|
atexit() {
|
|
group_id=`ps -p $$ -o pgid=`
|
|
my_id=$$
|
|
SED=`which gsed`
|
|
SED=$(basename "${SED:-sed}")
|
|
ids=`pgrep -g $group_id -d ' ' | ${SED} "s/\b$my_id\b//g"`
|
|
echo "Killing possible remaining process IDs: $ids"
|
|
for id in $ids
|
|
do
|
|
if ps -p $id > /dev/null
|
|
then
|
|
kill -9 $id
|
|
fi
|
|
done
|
|
exit ${rv}
|
|
}
|
|
|
|
trap "panic;" SIGINT SIGTERM
|
|
|
|
FORCE_FOREGROUND=$1
|
|
shift
|
|
|
|
source $1
|
|
shift
|
|
|
|
if [[ "${FORCE_FOREGROUND}" == "1" ]]
|
|
then
|
|
$*
|
|
else
|
|
$* &
|
|
pid=$!
|
|
wait ${pid}
|
|
fi
|
|
|
|
rv=$?
|
|
atexit
|
|
exit ${rv}
|