diff --git a/case-lib/hijack.sh b/case-lib/hijack.sh index 25b3690a..0f951b79 100644 --- a/case-lib/hijack.sh +++ b/case-lib/hijack.sh @@ -64,13 +64,10 @@ function func_exit_handler() # get ps command result as list local -a cmd_lst - # $$ as current script pid - # NOTICE: already test with $BASHPID: - # it can output the same result of $$ - # but the result could not be stored in the array - readarray -t cmd_lst < <(pgrep -P $$ -a|grep -v "$SCRIPT_NAME") + # can't run pgrep in any subshell because the latter would pollute the list + if pgrep -P $$ -a > "$LOG_ROOT/children_left.txt"; then + readarray -t cmd_lst < "$LOG_ROOT/children_left.txt" # now force kill target process which maybe block the script quit - if [ ${#cmd_lst[@]} -gt 0 ]; then local line dlogw "Process(es) started by $SCRIPT_NAME are still active, kill these process(es):" for line in "${cmd_lst[@]}" @@ -79,6 +76,8 @@ function func_exit_handler() dlogw "Kill cmd:'${line#* }' by kill -9" kill -9 "${line%% *}" done + else + rm "$LOG_ROOT/children_left.txt" fi # check if function already defined. diff --git a/case-lib/lib.sh b/case-lib/lib.sh index 074ea313..5a7982db 100644 --- a/case-lib/lib.sh +++ b/case-lib/lib.sh @@ -5,7 +5,7 @@ SCRIPT_HOME="$(dirname "$0")" # get test-case parent folder name SCRIPT_HOME=$(cd "$SCRIPT_HOME/.." && pwd) # shellcheck disable=SC2034 # external script can use it -SCRIPT_NAME="$0" # get test-case script load name +: "${SCRIPT_NAME:="$0"}" # get test-case script load name # shellcheck disable=SC2034 # external script can use it SCRIPT_PRAM="$*" # get test-case parameter diff --git a/case-lib/opt.sh b/case-lib/opt.sh index 593450f3..54296bbc 100644 --- a/case-lib/opt.sh +++ b/case-lib/opt.sh @@ -31,7 +31,7 @@ func_opt_parse_option() _func_case_dump_descption() { - grep '^##' "$SCRIPT_NAME"|sed 's/^##//g' + grep '^##' "$0"|sed 's/^##//g' } # Asks getopt to validate command line input and generate $_op_temp_script diff --git a/test-case/check-playback.sh b/test-case/check-playback.sh index 08d536b7..81dfd8b0 100755 --- a/test-case/check-playback.sh +++ b/test-case/check-playback.sh @@ -18,6 +18,7 @@ set -e +SCRIPT_NAME=BOGUS-check-playback # shellcheck source=case-lib/lib.sh source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh