tg.sh: make sure temporary directory is removed on signal
commit5841b9d8399fc5bead59276aa751b85ce064a6cb
authorKyle J. McKay <mackyle@gmail.com>
Sat, 19 Sep 2015 11:48:57 +0000 (19 04:48 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Sat, 19 Sep 2015 11:48:57 +0000 (19 04:48 -0700)
treeb61613e223ddf4ba0b55a6f38ba6551733e401e1
parent096430fbc812892bf335d7fb3a1f961be23ccd4a
tg.sh: make sure temporary directory is removed on signal

Only /bin/bash seems to trap all signals and run an EXIT
trap before terminating a script because of an uncaught
signal.  Other shells just die.

However, we rely on the EXIT trap to remove our temporary
directory.  Fix this by explicitly trapping the signals
we expect could terminate the script and explicitly calling
exit in the handler which will guarantee the EXIT trap
runs and does its thing.

When a process run by the shell dies of a signal, the exit
status is 128+signal, so use that as the exit status for
the various signals we trap on.

Additionally, POSIX defines 7 well-known signal numbers
that can be used.  We omit traps on ALRM and KILL.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
tg.sh