From 88789c8cde8c9f8ccf3eb016bb0dfc525e83f0dd Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Mon, 9 Apr 2018 22:33:22 +0100 Subject: [PATCH] test: Properly exit with non-0 status on errors SIGTERM can happen normally in our tests, and the current code has a trap that makes it trigger a clean exit. This causes some errors to be masked, as we end up calling "exit 0" when they occur. The error message will still be displayed, but the caller script will assume it worked. This patch fixes the problem by adjusting the bash signal handlers, so that we ignore SIGTERM (so bash does not get killed by the exit handler) and exit with error on SIGINT (triggered by ctrl-c). Note that under some conditions the SIGTERM trap is not necessary, but this depends on the environment. --- test/util/lib.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/util/lib.sh b/test/util/lib.sh index 4fe2ece..6e1b4ea 100644 --- a/test/util/lib.sh +++ b/test/util/lib.sh @@ -19,9 +19,9 @@ function init() { rm -rf .mail # Set traps to kill our subprocesses when we exit (for any reason). - # https://stackoverflow.com/questions/360201/ - trap "exit" INT TERM - trap "kill 0" EXIT + trap ":" TERM # Avoid the EXIT handler from killing bash. + trap "exit 2" INT # Ctrl-C, make sure we fail in that case. + trap "kill 0" EXIT # Kill children on exit. } function chasquid() {