diff options
Diffstat (limited to 'src/lib/libremessages')
-rwxr-xr-x | src/lib/libremessages | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/lib/libremessages b/src/lib/libremessages index 8e48c3b..df0a98a 100755 --- a/src/lib/libremessages +++ b/src/lib/libremessages @@ -117,6 +117,25 @@ term_title() { printf "$fmt" "$*" } +# Usage: setup_traps +# Sets up traps on TERM, HUP, QUIT and INT signals, as well as the ERR event, +# similar to makepkg +setup_traps() { + _libremessages_trap_exit() { + local signal=$1; shift + echo + error "$@" + trap -- "$signal" + kill "-$signal" "$$" + } + set -E + for signal in TERM HUP QUIT; do + trap "_libremessages_trap_exit $signal '%s signal caught. Exiting...' $signal" $signal + done + trap '_libremessages_trap_exit INT "Aborted by user! Exiting..."' INT + trap '_libremessages_trap_exit USR1 "An unknown error has occurred. Exiting..."' ERR +} + ################################################################################ # Run one of the defined functions if invoked directly # ################################################################################ |