Remove bashism
authorWouter Verhelst <w@uter.be>
Mon, 10 Oct 2016 20:54:24 +0000 (22:54 +0200)
committerWouter Verhelst <w@uter.be>
Mon, 10 Oct 2016 21:04:57 +0000 (23:04 +0200)
Running an EXIT trap on abnormal termination of the shell is a bashism;
dash, for instance, does not run them on SIGINT.

Fix by explicitly adding a trap for SIGINT.

Signed-off-by: Wouter Verhelst <w@uter.be>
tests/run/simple_test

index 0c05ea1..4b8aa6f 100755 (executable)
@@ -15,8 +15,6 @@ PID=""
 
 set -e
 
-trap cleanup EXIT
-
 cleanup() {
        if [ -f ${pidfile} ]
        then
@@ -25,6 +23,8 @@ cleanup() {
                if [ ! -z "$PID" ]
                then
                        kill $PID || true
+               else
+                       echo "E: Could not clean up!"
                fi
        fi
        if [ -z "$cleanup" ]
@@ -35,6 +35,15 @@ cleanup() {
        fi
 }
 
+abort() {
+       cleanup
+       trap - INT
+       kill -INT $$
+}
+
+trap -- cleanup EXIT
+trap -- abort INT
+
 # Create a one-meg device
 dd if=/dev/zero of=$tmpnam bs=1024 count=4096 >/dev/null 2>&1