commit 5a3f94777afc9c4458eef29689ea7dc36599e0e2
parent bd2997954d66a16334182c635876826ee3d65785
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date: Tue, 15 Dec 2015 12:44:03 +0100
change locking
Diffstat:
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/sbin/snap.lvm2 b/sbin/snap.lvm2
@@ -13,8 +13,10 @@ export SNAPSHOT
LOCKDIR=/var/lock/snaprep
test -d "$LOCKDIR" || mkdir -p "$LOCKDIR" || exit $?
LOCKFILE="$LOCKDIR/lvm2.${SRC//\//-}"
-exec 3> "$LOCKFILE" || exit $?
+# exec 3> "$LOCKFILE" || exit $?
+(
flock -n 3 || exit $?
+echo $$ >&3
if test -b "$S_DEV"; then
echo >&2 "removing stale snapshot"
if grep -qF "$S_DEV" /proc/mounts; then # TODO match only on start of line
@@ -45,5 +47,5 @@ touch $SNAP_SRC/.snapshot.$(date +%s)
RETCODE=$?
umount "$SNAPSHOT"
lvremove -f "$S_VOL"
-rm "$LOCKFILE"
+) 3> "$LOCKFILE"
exit $RETCODE