From 81a636ac871801ac1536d1965f42632d58f2f1ee Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Thu, 3 Dec 2020 22:09:28 -0800 Subject: [PATCH 1/3] exit handler: don't use a subshell to list children still running Use a new children_left.txt log file instead. Using a subshell forced us to filter it out with grep -v $SCRIPT_NAME which is more complicated, incompatible with exec wrappers like multiple-pipeline-capture/playback.sh and incompatible with running concurrent instances. Signed-off-by: Marc Herbert --- case-lib/hijack.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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. From 82cca816803ff2f0bdd3be6fe0186e337ca155cc Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Thu, 3 Dec 2020 22:24:29 -0800 Subject: [PATCH 2/3] opt.sh: extract test description from $0, not from $SCRIPT_NAME The SCRIPT_NAME indirection is not required and confusing. Signed-off-by: Marc Herbert --- case-lib/opt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From f4c939dafb1b0316893c1529e0b593f04d2d6962 Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Fri, 4 Dec 2020 10:52:34 -0800 Subject: [PATCH 3/3] TEST break logs/ subdirectory name for check-playback --- case-lib/lib.sh | 2 +- test-case/check-playback.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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/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