summaryrefslogtreecommitdiff
path: root/src/lib/libremessages
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2014-01-20 00:43:09 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2014-01-20 00:43:09 -0500
commit63362d52d3943f40fb96898a2b4e87e17f0adcf4 (patch)
tree7a1972add49eabb9ee0af4317e4ff11ec12c4b29 /src/lib/libremessages
parentb6e66bce4dadd1a5b9f74a456de3ef5575e648fa (diff)
libremessages: add a setup_traps routine
Diffstat (limited to 'src/lib/libremessages')
-rwxr-xr-xsrc/lib/libremessages19
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 #
################################################################################