From f4ed3ae9a222f121a1d4a18976ad0319dff4ad3d Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 21 Aug 2010 19:30:02 -0300 Subject: Making sure that the pid on lockfile reffers to an rsync backup process --- handlers/rsync.in | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'handlers/rsync.in') diff --git a/handlers/rsync.in b/handlers/rsync.in index cf304ed..f092812 100644 --- a/handlers/rsync.in +++ b/handlers/rsync.in @@ -849,7 +849,7 @@ function set_lockfile { if [ ! -z "$lockfile" ]; then mkdir -p `dirname $lockfile` if ( set -o noclobber; echo "$$" > "$lockfile" ) &> /dev/null; then - trap 'rm -f "$lockfile"' INT TERM EXIT + trap 'unset_lockfile' INT TERM EXIT else info "Could not create lockfile $lockfile, exiting" exit @@ -861,18 +861,19 @@ function set_lockfile { function unset_lockfile { if [ ! -z "$lockfile" ]; then - $rm $lockfile || warning "Could not remove lockfile $lockfile" + $rm -f $lockfile || warning "Could not remove lockfile $lockfile" fi } function check_lockfile { - local pid + local pid process if [ ! -z "$lockfile" ] && [ -f "$lockfile" ]; then pid="`cat $lockfile`" - if ps $pid &> /dev/null; then + process="`ps --no-headers -o comm $pid`" + if [ "$?" == "0" ] && [ "`ps --no-headers -o comm $$`" == "$process" ]; then info "Another backup is running for $lockfile, skipping run" exit else -- cgit v1.2.3