From: Peter Palfrader Date: Thu, 25 Apr 2013 13:53:15 +0000 (+0200) Subject: Try to fix a deadlock X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=0db182e876bfe2bc3388e182c9f6ec97071ada16;p=mirror%2Fdsa-puppet.git Try to fix a deadlock --- diff --git a/modules/roles/files/static-mirroring/static-master-ssh-wrap b/modules/roles/files/static-mirroring/static-master-ssh-wrap index d66f282fe..54c6f3459 100755 --- a/modules/roles/files/static-mirroring/static-master-ssh-wrap +++ b/modules/roles/files/static-mirroring/static-master-ssh-wrap @@ -51,25 +51,6 @@ croak() { exit 1 } -lock() { - local fd="$1"; shift - local path="$1"; shift - local exclusive="$1"; shift - - eval "exec $fd< '$path'" - - if [ "$exclusive" -gt 0 ]; then - locktype="-e" - else - locktype="-s" - fi - - if ! flock "$locktype" "$fd"; then - echo >&2 "$0: Cannot acquire lock on $base (flock $locktype failed) - Very bad, we should have waited!" - exit 1 - fi -} - do_rsync() { local remote_host="$1"; shift local args="--server --sender -vlHtrze.iLsf --safe-links ." @@ -83,7 +64,11 @@ do_rsync() { elif [ "$*" = "$args $component/-live-/" ] || [ "$*" = "$args ./$component/-live-/" ] ; then local path="$BASEDIR/master/$component-current-live" info "host $remote_host wants $path, acquiring lock" - lock 200 "$path" 0 + exec 200< "$path" + if ! flock -s -w 0 200; then + echo >&2 "Cannot acquire shared lock on $path - this means an update is already underway anyway (probably)." + exit 1 + fi rsync $args "$path/." return fi