From 7cd55a11575980fba5232c781b41fab469d00ec7 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Mon, 20 Sep 2021 09:12:58 +1200 Subject: [PATCH] move cleanup to earlier in script Signed-off-by: martin f. krafft --- pulserecorder | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) 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 -- 2.39.5