X-Git-Url: https://git.ao2.it/experiments/hook-lock.git/blobdiff_plain/6e3f2c8a7097aeccd1b7bda32e1b058a947e5c78..21dc816d9702893fa5b45c5c4d4b4b8edf0174d4:/exit-post-hook-unlock.sh diff --git a/exit-post-hook-unlock.sh b/exit-post-hook-unlock.sh index d618346..1db555f 100755 --- a/exit-post-hook-unlock.sh +++ b/exit-post-hook-unlock.sh @@ -14,9 +14,13 @@ set -e LOCKDIR=/run/lock/mylockdir +[ -d "$LOCKDIR" ] || exit 0 + 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.