This is an automated email from the ASF dual-hosted git repository.
aw pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/yetus.git
The following commit(s) were added to refs/heads/main by this push:
new 2d96197 YETUS-1076. precommit should mention it got a signal (#225)
2d96197 is described below
commit 2d961971f62f98fe7e15f7979712f292a42f2faa
Author: Allen Wittenauer <[email protected]>
AuthorDate: Mon Oct 25 07:01:28 2021 -0700
YETUS-1076. precommit should mention it got a signal (#225)
---
precommit/src/main/shell/buildkite-recovery.sh | 15 ++++++++++++++-
precommit/src/main/shell/core.d/00-yetuslib.sh | 15 +++++++++++++++
precommit/src/main/shell/core.d/01-common.sh | 14 ++++++++++++++
precommit/src/main/shell/core.d/docker.sh | 5 +++--
precommit/src/main/shell/docker-cleanup.sh | 4 ++--
precommit/src/main/shell/smart-apply-patch.sh | 3 ++-
precommit/src/main/shell/test-patch.sh | 2 ++
7 files changed, 52 insertions(+), 6 deletions(-)
diff --git a/precommit/src/main/shell/buildkite-recovery.sh
b/precommit/src/main/shell/buildkite-recovery.sh
index 4e9f531..d5856b6 100755
--- a/precommit/src/main/shell/buildkite-recovery.sh
+++ b/precommit/src/main/shell/buildkite-recovery.sh
@@ -148,12 +148,25 @@ function setup_parameter_tracker
done
}
-trap "cleanup_and_exit 1" HUP INT QUIT TERM
+## @description Clean the filesystem as appropriate and then exit
+## @audience private
+## @stability evolving
+## @replaceable no
+## @param runresult
+function cleanup_and_exit
+{
+ local result=$1
+
+ # shellcheck disable=SC2086
+ exit ${result}
+}
setup_parameter_tracker
import_core
+yetus_set_trap_handler generic_signal_handler HUP INT QUIT TERM
+
setup_defaults
parse_args "$@"
diff --git a/precommit/src/main/shell/core.d/00-yetuslib.sh
b/precommit/src/main/shell/core.d/00-yetuslib.sh
index 1ef0607..9cb7a2f 100755
--- a/precommit/src/main/shell/core.d/00-yetuslib.sh
+++ b/precommit/src/main/shell/core.d/00-yetuslib.sh
@@ -513,3 +513,18 @@ function yetus_get_ctime
date +"%s"
fi
}
+
+## @description Set a trap passing the first param as the signal
+## @audience public
+## @stability stable
+## @param function
+## @param signal
+## @param [signal]
+function yetus_set_trap_handler
+{
+ local func="$1" ; shift
+ for signal ; do
+ # shellcheck disable=SC2064
+ trap "${func} ${signal}" "${signal}"
+ done
+}
diff --git a/precommit/src/main/shell/core.d/01-common.sh
b/precommit/src/main/shell/core.d/01-common.sh
index 2ab4f21..0b74383 100755
--- a/precommit/src/main/shell/core.d/01-common.sh
+++ b/precommit/src/main/shell/core.d/01-common.sh
@@ -909,3 +909,17 @@ function escape_html
str="${str//\'/'}"
echo "${str}"
}
+
+## @description When getting a signal, mention the signal then
+## @description die by calling cleanup_and_exit. Expected to be
+## @description used with yetus_set_trap_handler
+## @audience private
+## @stability evolving
+## @replaceable no
+function generic_signal_handler
+{
+ declare trapid=$1
+
+ yetus_error "ERROR: Caught signal ${trapid}."
+ cleanup_and_exit 143 # 128 + 15 -- SIGTERM
+}
diff --git a/precommit/src/main/shell/core.d/docker.sh
b/precommit/src/main/shell/core.d/docker.sh
index 8e18199..b5b0387 100755
--- a/precommit/src/main/shell/core.d/docker.sh
+++ b/precommit/src/main/shell/core.d/docker.sh
@@ -842,7 +842,7 @@ function docker_run_image
DOCKER_EXTRAARGS+=(--name "${containername}")
- trap 'docker_signal_handler' SIGTERM SIGINT SIGHUP
+ yetus_set_trap_handler docker_signal_handler HUP INT QUIT TERM
if [[ ${PATCH_DIR} =~ ^/ ]]; then
dockercmd run --rm=true -i \
@@ -874,11 +874,12 @@ function docker_run_image
## @replaceable no
function docker_signal_handler
{
+ declare signal=$1
declare cid
cid=$(cat "${PATCH_DIR}/cidfile.txt")
- yetus_error "ERROR: Caught signal. Killing docker container:"
+ yetus_error "ERROR: Caught signal ${signal}. Killing docker container:"
echo "ERROR: Caught signal. Killing docker container: ${cid}" >
"${PATCH_DIR}/signal.log"
dockercmd kill "${cid}" | tee -a "${PATCH_DIR}/signal.log"
rm "${PATCH_DIR}/cidfile.txt"
diff --git a/precommit/src/main/shell/docker-cleanup.sh
b/precommit/src/main/shell/docker-cleanup.sh
index 910c7f5..d8d407f 100755
--- a/precommit/src/main/shell/docker-cleanup.sh
+++ b/precommit/src/main/shell/docker-cleanup.sh
@@ -205,12 +205,12 @@ function setup_parameter_tracker
done
}
-trap "cleanup_and_exit 1" HUP INT QUIT TERM
-
setup_parameter_tracker
import_core
+yetus_set_trap_handler generic_signal_handler HUP INT QUIT TERM
+
setup_defaults
parse_args "$@"
diff --git a/precommit/src/main/shell/smart-apply-patch.sh
b/precommit/src/main/shell/smart-apply-patch.sh
index 01af8db..fb10764 100755
--- a/precommit/src/main/shell/smart-apply-patch.sh
+++ b/precommit/src/main/shell/smart-apply-patch.sh
@@ -407,7 +407,6 @@ function setup_parameter_tracker
done
}
-trap "cleanup_and_exit 1" HUP INT QUIT TERM
# robots will change USER_PARAMS so must
# do this before importing other code
@@ -415,6 +414,8 @@ setup_parameter_tracker
import_core
+yetus_set_trap_handler generic_signal_handler HUP INT QUIT TERM
+
setup_defaults
parse_args "$@"
diff --git a/precommit/src/main/shell/test-patch.sh
b/precommit/src/main/shell/test-patch.sh
index 5d4d253..01b3283 100755
--- a/precommit/src/main/shell/test-patch.sh
+++ b/precommit/src/main/shell/test-patch.sh
@@ -3263,6 +3263,8 @@ setup_parameter_tracker
import_core
+yetus_set_trap_handler generic_signal_handler HUP INT QUIT TERM
+
if [[ "${BINNAME}" =~ qbt ]]; then
initialize --empty-patch "$@"
else