Article Listing 1 Listing 2 Listing 3 Listing 4
Listing 5 Listing 6 Listing 7 Listing 8 Listing 9
Listing 10 Listing 11 Listing 12 Listing 13 Sidebar aug2004.tar

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
}