#
# lock functions
#					Shuu Yamaguchi <shuu@dotAster.com>
# $Id: func_lock,v 1.4 2004/04/06 14:47:08 shuu Exp shuu $

if [ -n "$MURASAKI_FUNC_LOCK" ];then
	return
fi
MURASAKI_FUNC_LOCK=1

. ${MURASAKI_SCRIPT_DIR}/func_log

# $1:uniq key
lock_file()
{
	for sec in 1 1 1 2 2 2 
	do
		if [ -f ${MURASAKI_CONF_DIR}/lock$1 ];then
			sleep $sec
		else
			break
		fi
	done
	if [ -f ${MURASAKI_CONF_DIR}/lock$1 ];then
		log "daemon.err" "murasaki:lock_file" "${MURASAKI_CONF_DIR}/lock$1 keep existing."
		exit 1
	fi
	touch ${MURASAKI_CONF_DIR}/lock$1
}

# $1:uniq key
unlock_file()
{
	rm -f ${MURASAKI_CONF_DIR}/lock$1
}
