summaryrefslogtreecommitdiffhomepage
path: root/subr
diff options
context:
space:
mode:
authorLucio Andrés Illanes Albornoz <lucio@lucioillanes.de>2020-02-11 17:09:33 +0000
committerLucio Andrés Illanes Albornoz <lucio@lucioillanes.de>2020-02-11 17:09:33 +0000
commit6c366071bd3ec4c423d8155509280f88e55a3ebc (patch)
treee6855b3e35de0e07e099f799a30bfade390ef691 /subr
parent8a04deff7e91795435db7b751352512f116c7aba (diff)
downloadmidipix_build-6c366071bd3ec4c423d8155509280f88e55a3ebc.tar.bz2
midipix_build-6c366071bd3ec4c423d8155509280f88e55a3ebc.tar.xz
subr/build_init.subr:build_{ast,init}(): call ex_rtl_kill_tree() on $$ on signal.
subr/build_init.subr:build_init(): check for pgrep(1) in $PATH. subr/ex_rtl.subr:ex_rtl_kill_tree(): implement w/ pgrep(1).
Diffstat (limited to 'subr')
-rw-r--r--subr/build_init.subr18
-rw-r--r--subr/ex_rtl.subr10
2 files changed, 23 insertions, 5 deletions
diff --git a/subr/build_init.subr b/subr/build_init.subr
index fd91a6f0..01ae9be7 100644
--- a/subr/build_init.subr
+++ b/subr/build_init.subr
@@ -1,3 +1,12 @@
+build_ast() {
+ local _param="${1}" _pids_killed="";
+ rm -f "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}";
+ case "${_param}" in
+ abort) ex_rtl_log_msg failexit "Build aborted."; ;;
+ esac;
+ ex_rtl_kill_tree "${$}"; ex_rtl_log_msg vnfo "Killed PIDs ${_pids_killed}";
+};
+
build_fini() {
: $((BUILD_TIMES_SECS=$(ex_rtl_date %s)-${BUILD_TIMES_SECS}));
: $((BUILD_TIMES_HOURS=${BUILD_TIMES_SECS}/3600));
@@ -14,6 +23,9 @@ build_init() {
if ! awk -V 2>/dev/null | grep -q "^GNU Awk "; then
ex_rtl_log_msg failexit "Error: awk(1) in \$PATH must be GNU Awk.";
fi;
+ if ! which pgrep >/dev/null 2>&1; then
+ ex_rtl_log_msg failexit "Error: missing pgrep.";
+ fi;
if [ -z "${DEFAULT_BUILD_CPUS}" ]\
&& [ -e /proc/cpuinfo ]; then
DEFAULT_BUILD_CPUS=$(awk '/^processor/{cpus++} END{print cpus}' /proc/cpuinfo);
@@ -81,11 +93,7 @@ build_init() {
BUILD_NFINI="${BUILD_NSKIP:=${BUILD_NFAIL:=${BUILD_NBUILT:=0}}}";
BUILD_TIMES_SECS="$(ex_rtl_date %s)";
BUILD_PKGS_FAILED="";
- trap "rm -f "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}"; \
- ex_rtl_log_msg failexit \"Build aborted.\";" \
- HUP INT TERM USR1 USR2;
- trap "rm -f "${DEFAULT_BUILD_STATUS_IN_PROGRESS_FNAME}";" \
- EXIT;
+ trap "build_ast abort" HUP INT TERM USR1 USR2; trap "build_ast exit" EXIT;
for _vname in ${DEFAULT_CHECK_PATH_VARS}; do
_vname_val="$(ex_rtl_get_var_unsafe "${_vname}")";
if [ -z "${_vname_val}" ]; then
diff --git a/subr/ex_rtl.subr b/subr/ex_rtl.subr
index 3f5e8c70..6bbbe5e4 100644
--- a/subr/ex_rtl.subr
+++ b/subr/ex_rtl.subr
@@ -17,6 +17,16 @@ ex_rtl_toupper() { echo "${1}" | tr a-z A-Z; };
ex_rtl_uniq() { echo "${@}" | sed 's/ /\n/g' | awk '!x[$0]++' | paste -s -d" "; };
ex_rtl_unset_vars() { while [ ${#} -gt 0 ]; do unset "${1}"; shift; done; };
+ex_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;
+ done;
+ _pids_killed="${_pids_killed:+${_pids_killed} }${_pid_child}"; kill "-${_signal}" "${_pid_child}" 2>/dev/null;
+ done;
+};
+
ex_rtl_lfilter() {
local _list="${1}" _filter="${2}" _lnew="" _litem="" _litem_filter="" _filterfl="";
if [ -z "${_filter}" ]; then