#!/bin/sh
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#
# Lock the PMNS against concurrent transactional updates
#
# $Revision: 1.8 $
#

. /etc/pcp.env

lock=${1-$PCP_VAR_DIR/pmns/root}.lock

i=0
while true
do
    if pmlock $lock
    then
	# lock acquired
	#
	#DEBUG# echo "pmnslock: `date; ls -li $lock`"
	break
    fi
    if [ $i -eq 20 ]
    then
	echo "lockpmns: Warning: Unable to acquire lock ($lock)"
	echo "                   after 120 seconds ... continuing anyway"
	exit 1
    fi
    sleep 5
    i=`expr $i + 1`
done

exit 0
