#!/bin/sh vo_sw_dir=${HOME}/vosw error() { echo $@ exit 1 } log() { echo LOG: $@ } get_write_lock() { log "Checking if the vo software area is writable." if [ -z $vo_sw_dir ] ; then error "\$$vo_sw_dir_var not set." fi if [ ! -w $vo_sw_dir ] ; then error "\$$vo_sw_dir_var ($vo_sw_dir) is not writable. (Check your proxy: are you the VO software manager?)" fi log "$vo_sw_dir writable OK." # now do the lockfile shuffle lockfile=$vo_sw_dir/pkgsrc-lock log "checking lockfile $lockfile" if [ -f $lockfile ]; then log "lockfile exists." ls -l $lockfile if [ -z `find $lockfile -mmin -30` ]; then log "stale lockfile ($lockfile is older than 30 minutes)" rm -f $lockfile || error "could not remove $lockfile. Call help." else log "lockfile is still fresh." return 1 fi else log "no lockfile found. Setting lock" fi # At this point, we've concluded we should try and set the lockfile. # be careful to avoid race conditions (although rare). log "attempting to get lock." a=`mktemp $vo_sw_dir/pkgsrc-lock.XXXXXXXXXX` || error "mktemp failed" ln $a $lockfile if [ $? -ne 0 ]; then log "failed to obtain lock" rm $a return 1 fi log "lock set" rm $a unset a trap "rm -f $lockfile" INT TERM EXIT return 0 } echo "try 1:" get_write_lock if [ $? -ne 0 ]; then echo fail else echo ok fi echo "try 2:" get_write_lock if [ $? -ne 0 ]; then echo fail else echo ok fi