improve sub-proc handling / killing
This commit is contained in:
@@ -598,24 +598,30 @@ while :; do
|
|||||||
read -t 0 -u $fd
|
read -t 0 -u $fd
|
||||||
(( $? == 0 )) || continue
|
(( $? == 0 )) || continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
data=$(timeout 1 cat <&$fd)
|
data=$(timeout 1 cat <&$fd)
|
||||||
rc=$?
|
rc=$?
|
||||||
eval "exec $fd>&-"
|
eval "exec $fd>&-"
|
||||||
fdtable[$func]=-1
|
fdtable[$func]=-1
|
||||||
|
|
||||||
pid=${pidtable[$func]}
|
pid=${pidtable[$func]}
|
||||||
if (( rc == 124 )); then
|
if (( rc == 124 )); then
|
||||||
echo "gather: timeout receiving data from $func (PID $pid, FD $fd), killing process" >&2
|
echo "gather: timeout receiving data from $func (PID $pid, FD $fd), sending SIGTERM" >&2
|
||||||
kill -SIGTERM $pid
|
kill -SIGTERM $pid
|
||||||
sleep 1
|
sleep 1
|
||||||
ps -p $pid >/dev/null && kill -SIGKILL $pid
|
if ps -p $pid >/dev/null; then
|
||||||
rc=137
|
echo "gather: unable to terminate $func (PID $pid, FD $fd), sending SIGKILL" >&2
|
||||||
else
|
kill -SIGKILL $pid
|
||||||
|
fi
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
wait $pid &>/dev/null
|
wait $pid &>/dev/null
|
||||||
rc=$?
|
rc=$?
|
||||||
# the wait function in older Bash versions prior to 5.1 always returns 127 if
|
# the wait function in older Bash versions prior to 5.1 always returns 127 if the
|
||||||
# the sub-process already exited at this point
|
# sub-process already exited at this point
|
||||||
(( rc == 127 )) && rc=0
|
(( rc == 127 )) && rc=0
|
||||||
fi
|
|
||||||
echo "gather: $func (PID $pid, FD $fd) exited with rc = $rc" >&$DEBUGLOG
|
echo "gather: $func (PID $pid, FD $fd) exited with rc = $rc" >&$DEBUGLOG
|
||||||
if (( rc == 0 )) && [ -n "$data" ]; then
|
if (( rc == 0 )) && [ -n "$data" ]; then
|
||||||
echo "gather: sending data to cache" >&$DEBUGLOG
|
echo "gather: sending data to cache" >&$DEBUGLOG
|
||||||
|
|||||||
Reference in New Issue
Block a user