From: Alexander Schmidt Date: Wed, 11 Feb 2015 20:13:59 +0000 (+0100) Subject: Use flock for locking. X-Git-Url: http://git.treefish.org/~alex/backmeupscotty.git/commitdiff_plain/aad0734411ecf750bf2233dba6cffb333da50d68 Use flock for locking. --- diff --git a/backmeupscotty b/backmeupscotty index be1ce20..44e9c54 100644 --- a/backmeupscotty +++ b/backmeupscotty @@ -125,12 +125,6 @@ function scottysync { done } -function deleteLock { - if ! rmdir /tmp/$(basename $0).lock; then - scottyerror "Could not delete lockfile /tmp/$(basename $0).lock!" - fi -} - function prepare { scottyinfo "Preparing for sync." } @@ -145,8 +139,6 @@ function cleanup_abort { kill $(jobs -p) fi - deleteLock - exit } @@ -158,11 +150,6 @@ function prepare { scottyinfo "No prepare function was defined." } -function cleanup_normal { - cleanup - deleteLock -} - function printhelp { cat </var/run/$(basename $0).pid +if ! flock -n 200; then scottyerror "Another instance of $(basename $0) is still running!" exit 1 -else - trap deleteLock EXIT fi +echo $$ 1>&200