From fa4a80dd5993cc64a72c92a450b3a25e3949eb4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Sat, 29 Feb 2020 13:17:19 +0000 Subject: build.sh:buildp_ast(): correctly call rtl_kill_tree(). subr/rtl_complex.subr:rtl_kill_tree(): iteratively & recursively kill tree of processes excluding ${$}. --- subr/rtl_complex.subr | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'subr') diff --git a/subr/rtl_complex.subr b/subr/rtl_complex.subr index 6d9750dc..8370a4cf 100644 --- a/subr/rtl_complex.subr +++ b/subr/rtl_complex.subr @@ -75,13 +75,17 @@ rtl_head() { }; rtl_kill_tree() { - local _pid="${1}" _signal="TERM" _pid_child="" _pid_top=""; - for _pid_top in $(pgrep -P "${_pid}"); do - for _pid_child in $(pgrep -P "${_pid_top}" 2>/dev/null); do - _pids_killed="${_pids_killed:+${_pids_killed} }${_pid_child}"; kill "-${_signal}" "${_pid_child}" 2>/dev/null; + local _pid="${1}" _signal="${2:-TERM}" _pid_child="" _pids=""; + if _pids="$(pgrep -P "${_pid}")"\ + && [ -n "${_pids}" ]; then + for _pid_child in ${_pids}; do + rtl_kill_tree "${_pid_child}" "${_signal}"; done; - _pids_killed="${_pids_killed:+${_pids_killed} }${_pid_top}"; kill "-${_signal}" "${_pid_top}" 2>/dev/null; - done; + fi; + if [ "${_pid:-0}" -ne "${$}" ]\ + && kill "-${_signal}" "${_pid}" 2>/dev/null; then + RTL_KILL_TREE_PIDS="$(rtl_lconcat "${RTL_KILL_TREE_PIDS}" "${_pid}")"; + fi; }; rtl_run_cmd_unsplit() { -- cgit v1.2.3