summaryrefslogtreecommitdiff
path: root/src
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
parentb6e66bce4dadd1a5b9f74a456de3ef5575e648fa (diff)
libremessages: add a setup_traps routine
Diffstat (limited to 'src')
-rwxr-xr-xsrc/lib/libremessages19
-rw-r--r--src/lib/libremessages.1.ronn4
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