Listing 6 is_initialized
{
# Returns 0 if a semaphore exists and is initialized; otherwise, returns
# 1. The semaphore $semaphore exists and is initialized if the symbolic
# link $HOME_DIR/$semaphore/$RESOURCES_FILENAME exists and points to a
# "filename" that is a non-negative integer.
local FUNC_NAME=is_initialized
${TRACE:-trace $FUNC_NAME $@}
local semaphore=$1
integer num_resources
local resources_file=$HOME_DIR/$semaphore/$RESOURCES_FILENAME
if [[ -f $resources_file ]]
then
if is_non_negative_integer $(cat -s $resources_file)
then
${INFO:-info "Semaphore $semaphore is initialized."}
return 0
fi
fi
${INFO:-info "Semaphore $semaphore is not initialized."}
return 1
} |