improve handling / killing of hanging background procs

This commit is contained in:
2024-11-02 01:07:11 +01:00
parent ce2daf9749
commit 6ec4c02e40

View File

@@ -600,16 +600,20 @@ while :; do
fi
data=$(timeout 1 cat <&$fd)
rc=$?
eval "exec $fd>&-"
fdtable[$func]=-1
pid=${pidtable[$func]}
if (( rc == 124 )); then
echo "gathering: timeout receiving data from $func (PID $pid, FD $fd), killing process" >&2
kill -9 $pid
fi
kill -SIGTERM $pid
sleep 1
ps -p $pid >/dev/null && kill -SIGKILL $pid
rc=137
else
wait $pid
rc=$?
echo "gathering: $func exited (rc = $rc)" >&$DEBUGLOG
eval "exec $fd>&-"
fdtable[$func]=-1
fi
echo "gathering: $func (PID $pid, FD $fd) exited with rc = $rc" >&$DEBUGLOG
if (( rc == 0 )) && [ -n "$data" ]; then
echo "gathering: sending data to main" >&$DEBUGLOG
echo "$data" 1>&$DATAIN