safelock.c
/* Atomically fetch the status for a Safelock on disk */
Atomically fetch the status for a Safelock on disk
Atomically fetch the status for a Safelock on disk
int safelock_fetch_file_status(const char *filename,
                               safelock_status_t *status)
{
    safelock_t lock;
    int ret;
    int err;
    assert(filename);
    assert(status);
    ret = access(filename, F_OK);
    if (ret < 0) {
        if (errno == ENOENT) {
            memset(status, 0, sizeof(*status));
            return 0;
        }
        return errno;
    }
    err = safelock_open(&lock, filename, 0);
    if (err)
        return err;
    err = safelock_fetch_status(lock, status);
    safelock_close(&lock);
    return err;
}
int safelock_fetch_file_status ( const char * filename , safelock_status_t * status ) { safelock_t lock ; int ret ; int err ; assert ( filename ) ; assert ( status ) ; ret = access ( filename , F_OK ) ; if ( ret < 0 ) { if ( errno == ENOENT ) { memset ( status , 0 , sizeof ( * status ) ) ; return 0 ; } return errno ; } err = safelock_open ( & lock , filename , 0 ) ; if ( err ) return err ; err = safelock_fetch_status ( lock , status ) ; safelock_close ( & lock ) ; return err ; }
Atomically fetch the status for a Safelock on disk
Atomically fetch the status for a Safelock on disk
/* Does the lock file exist? */ /* Return !locked if it doesn't exist */ /* locked = 0, crashed = 0, data_valid = 0 */ /* Return an error if the access() check failed */ /* Lockfile exists, check lock status */