NWChem/src/config/lockfile
Huub Van Dam 97f303e6f8 HvD: In the CVS era the $Id: $ tags in the source code files would
automatically be expanded to include useful information about the
checkin (including the file's revision number). With the switch over
to SVN this was lost because SVN only does this expansion if you 
explicitly ask for it (for every single file). 

I have added a script to the contrib directory that sets the appropriate
property to get SVN to do this expansion. This script will make it easy
to do this every time new source files are added. It is called
svn_expand_Id, the script contains some comments that explain the issue
and how it addresses this.  

This checkin sets this property for a subset of the relevant files
(trying to commit all files at once failed with svn crashing). 
In future the script will only affect those files for which the property
was not set before.
2010-10-29 18:04:21 +00:00

85 lines
1.5 KiB
Bash
Executable file

#!/bin/sh
#
# $Id$
#
#
# lockfile [-steal] filename
#
# Simluate a lock by creating and writing the specified file.
# The lock may be released by deleting the file. If -steal
# is specified then the lock is stolen instead of exiting on timeout.
#
# On sucess exits with status zero and access to the lock
#
# All other conditions exit with status one and undefined lock state.
#
# Some race conditions exist but deadlock is avoided by exiting/stealing
# if the lock is not acquired in TIMEOUT*SECS seconds
#
# SECS is the time in seconds to sleep between tries to get the lock
# TIMEOUT*SECS is the time in seconds before waiting is abandonned.
#
# BGJ - rewritten in Bourne shell for Cygnus NT port
#
TIMEOUT=12
SECS=2
unset STEAL
unset USAGE
if [ $# -eq 2 ] ; then
if [ "$1" = "-steal" ] ; then
STEAL=1
shift
else
USAGE=1
fi
elif [ $# -ne 1 -o "$1" = "-steal" ] ; then
USAGE=1
fi
if [ $USAGE ] ; then
echo 'usage: lockfile [-steal] filename'
exit 1
fi
file=$1
DOWAIT=1
nspin=0
while [ $DOWAIT ] ; do
while [ -f $file ] ; do
if [ $nspin -ge $TIMEOUT ] ; then
if [ $STEAL ] ; then
echo lockfile: stealing $file
/bin/rm -f $file
else
echo lockfile: timeout waiting for $file ... delete it\!
exit 1
fi
else
nspin=`expr $nspin + 1`
echo lockfile: waiting for $file
sleep $SECS
fi
done
echo $$ " " > $file
id="`cat $file`"
if [ $id -ne $$ ] ; then
echo lockfile: not fast enough on $file
else
unset DOWAIT
fi
done
echo Got lock on $file
exit 0