From: martin f. krafft Date: Sun, 19 Sep 2021 21:12:58 +0000 (+1200) Subject: move cleanup to earlier in script X-Git-Url: https://git.madduck.net/code/pulserecorder.git/commitdiff_plain/7cd55a11575980fba5232c781b41fab469d00ec7 move cleanup to earlier in script Signed-off-by: martin f. krafft --- diff --git a/pulserecorder b/pulserecorder index 65a40ce..a9f4cdc 100755 --- a/pulserecorder +++ b/pulserecorder @@ -20,6 +20,17 @@ # set -eu +cleanup_commands= +cleanup() { + set +e + eval $cleanup_commands 2>/dev/null + trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15 +} +trap cleanup 1 2 3 4 5 6 7 8 10 11 12 13 14 15 +cleanup_hook() { + cleanup_commands="$@${cleanup_commands:+; $cleanup_commands}" +} + if [ -z "${TMPDIR:-}" ]; then TMPDIR=/tmp fi @@ -31,17 +42,8 @@ for i in $LOGNAME volatile; do done export TMPDIR TMPDIR=$(mktemp -dp "$TMPDIR" parec.XXXXXXXXXX) +cleanup_hook rm -r $TMPDIR -cleanup_commands="rm -r $TMPDIR" -cleanup() { - set +e - eval $cleanup_commands 2>/dev/null - trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15 -} -trap cleanup 1 2 3 4 5 6 7 8 10 11 12 13 14 15 -cleanup_hook() { - cleanup_commands="$@${cleanup_commands:+; $cleanup_commands}" -} state= outfile= index= clobber=0 for arg in "$@"; do