diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/lib/libremessages | 19 | ||||
-rw-r--r-- | src/lib/libremessages.1.ronn | 4 |
2 files changed, 23 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 # ################################################################################ diff --git a/src/lib/libremessages.1.ronn b/src/lib/libremessages.1.ronn index bf052bd..d4c35fc 100644 --- a/src/lib/libremessages.1.ronn +++ b/src/lib/libremessages.1.ronn @@ -69,6 +69,10 @@ Unless otherwise noted, these do not implicitly call `gettext`. Joins all arguments with whitespace, and sets the terminal title to that. + * `setup_traps`: + Sets traps on TERM, HUP, QUIT and INT signals, as sell as the ERR + event, similar to makepkg. + ### PROSE ROUTINES These routines print to standard output, ande are useful for printing |