From 21dc816d9702893fa5b45c5c4d4b4b8edf0174d4 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Thu, 13 Dec 2018 16:34:53 +0100 Subject: [PATCH 1/1] exit-post-hook-unlock.sh: use a trap to release the lock Use a trap to release the lock, this way the lock would be more robustly released when the exit hook is called, even if some commands in the exit hook failed. --- exit-post-hook-unlock.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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. -- 2.1.4