X-Git-Url: https://git.ao2.it/experiments/hook-lock.git/blobdiff_plain/2144a1fa25d58c93677c110bcbfdc58023d0cf45..HEAD:/exit-post-hook-unlock.sh diff --git a/exit-post-hook-unlock.sh b/exit-post-hook-unlock.sh index 02d3648..1db555f 100755 --- a/exit-post-hook-unlock.sh +++ b/exit-post-hook-unlock.sh @@ -19,6 +19,8 @@ LOCKDIR=/run/lock/mylockdir LOCKPID=$(cat "$LOCKDIR/pid") [ "$LOCKPID" = $PPID ] || { echo "The enter script was launched from another process. Unlocking aborted." >&2; exit 1; } -# Do stuff here +# Use a trap to release the lock even if the commands below fail. +trap 'rm -rf "$LOCKDIR"' EXIT +trap 'exit 2' HUP INT QUIT PIPE TERM -rm -rf "$LOCKDIR" +# Do stuff here.