aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-16 18:38:49 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-16 18:38:49 +1200
commit0b1c99ffb1c3019e8afb9dcc542fbc5e868baef1 (patch)
tree9712aa161c25232e0f6561ee181b82eb42af347a /bin
parentPut "all" subtargets on their own line (diff)
downloaddotfiles-0b1c99ffb1c3019e8afb9dcc542fbc5e868baef1.tar.gz
dotfiles-0b1c99ffb1c3019e8afb9dcc542fbc5e868baef1.zip
Template traps in scripts depending on mktd(1)
Diffstat (limited to 'bin')
-rw-r--r--[-rwxr-xr-x]bin/rndl.m4 (renamed from bin/rndl)16
-rw-r--r--[-rwxr-xr-x]bin/tlcs.m4 (renamed from bin/tlcs)16
-rw-r--r--[-rwxr-xr-x]bin/try.m4 (renamed from bin/try)18
-rw-r--r--[-rwxr-xr-x]bin/urlc.m4 (renamed from bin/urlc)14
4 files changed, 5 insertions, 59 deletions
diff --git a/bin/rndl b/bin/rndl.m4
index 2ac3bf47..85b21545 100755..100644
--- a/bin/rndl
+++ b/bin/rndl.m4
@@ -7,21 +7,7 @@
# file if we don't want to read all of the input into memory (!)
if [ "$#" -eq 0 ] ; then
- # Try to create the temporary directory with mktd(1) safely
- td=
- cleanup() {
- [ -n "$td" ] && rm -fr -- "$td"
- if [ "$1" != EXIT ] ; then
- trap - "$1"
- kill "-$1" "$$"
- fi
- }
- for sig in EXIT HUP INT TERM ; do
- # shellcheck disable=SC2064
- trap "cleanup $sig" "$sig"
- done
- td=$(mktd rndl) || exit
-
+include(`include/mktd.trap.sh')
# We'll operate on stdin in the temp directory; write the script's stdin to
# it with cat(1)
set -- "$td"/stdin
diff --git a/bin/tlcs b/bin/tlcs.m4
index dcd76c7d..ff01cc0d 100755..100644
--- a/bin/tlcs
+++ b/bin/tlcs.m4
@@ -67,21 +67,7 @@ if [ "$((color_count >= 8))" -eq 1 ] ; then
fi
fi
-# Temporary directory for the FIFOs
-td=
-cleanup() {
- [ -n "$td" ] && rm -fr -- "$td"
- if [ "$1" != EXIT ] ; then
- trap - "$1"
- kill "-$1" "$$"
- fi
-}
-for sig in EXIT HUP INT TERM ; do
- # shellcheck disable=SC2064
- trap "cleanup $sig" "$sig"
-done
-td=$(mktd "$self") || exit
-
+include(`include/mktd.trap.sh')
# Execute the command, passing stdout and stderr to tl(1) calls as appropriate
# via named pipes
out=$td/out err=$td/err
diff --git a/bin/try b/bin/try.m4
index f0ba317d..359a4280 100755..100644
--- a/bin/try
+++ b/bin/try.m4
@@ -26,23 +26,9 @@ if [ "$#" -eq 0 ] ; then
exit 2
fi
-# Create a buffer file for the error output, and clean up the file when we exit
-td=
-cleanup() {
- [ -n "$td" ] && rm -fr -- "$td"
- if [ "$1" != EXIT ] ; then
- trap - "$1"
- kill "-$1" "$$"
- fi
-}
-for sig in EXIT HUP INT TERM ; do
- # shellcheck disable=SC2064
- trap "cleanup $sig" "$sig"
-done
-td=$(mktd "$self") || exit
-errbuff=$td/errbuff
-
+include(`include/mktd.trap.sh')
# Open a filehandle to the error buffer, just to save on file operations
+errbuff=$td/errbuff
exec 3>"$errbuff"
# Keep trying the command, writing error output to the buffer file, and exit
diff --git a/bin/urlc b/bin/urlc.m4
index 63f075bf..c49c1ecf 100755..100644
--- a/bin/urlc
+++ b/bin/urlc.m4
@@ -5,21 +5,9 @@ self=urlc
# cURL request timeout
tm=${URLCHECK_TIMEOUT:-8}
+include(`include/mktd.trap.sh')
# Create buffer files for the headers and body content, to be cleaned up on
# exit
-td=
-cleanup() {
- [ -n "$td" ] && rm -fr -- "$td"
- if [ "$1" != EXIT ] ; then
- trap - "$1"
- kill "-$1" "$$"
- fi
-}
-for sig in EXIT HUP INT TERM ; do
- # shellcheck disable=SC2064
- trap "cleanup $sig" "$sig"
-done
-td=$(mktd "$self") || exit
list=$td/list head=$td/head body=$td/body
# Iterate through input; ignore leading/trailing whitespace