Changeset 896


Ignore:
Timestamp:
Mar 21, 2016, 2:30:06 PM (9 years ago)
Author:
Silvan Scherrer
Message:

tdb: Ignore failed attempt to O_TRUNC the lock file.

This will happen if the file is already open by another process
that has locked some bytes and means the file is already empty.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/lib/tdb/common/open.c

    r895 r896  
    1  /* 
     1 /*
    22   Unix SMB/CIFS implementation.
    33
     
    120120}
    121121
    122 /* open the database, creating it if necessary 
     122/* open the database, creating it if necessary
    123123
    124124   The open_flags and mode are passed straight to the open call on the
     
    126126   is advisory, use zero for a default value.
    127127
    128    Return is NULL on error, in which case errno is also set.  Don't 
     128   Return is NULL on error, in which case errno is also set.  Don't
    129129   try to call tdb_error or tdb_errname, just do strerror(errno).
    130130
     
    172172        char lock_name[_MAX_PATH + 5];
    173173        snprintf(lock_name, sizeof(lock_name), "%s.lock", name);
     174        /*
     175         * First try to O_TRUNC it to make sure the file is empty (this
     176         * will succeed on first open), but ignore the error that will
     177         * happen if some bytes are already locked.
     178         */
    174179        tdb->lock_fd = open(lock_name, tdb->open_flags | O_CREAT | O_TRUNC, 0777);
     180        if (tdb->lock_fd == -1 && errno == EACCES)
     181                tdb->lock_fd = open(lock_name, tdb->open_flags | O_CREAT, 0777);
    175182        if (tdb->lock_fd == -1) {
    176183                TDB_LOG((tdb, TDB_DEBUG_ERROR, "os2_create_lockfile: cannot create lock file %s, errno=%d\n",
Note: See TracChangeset for help on using the changeset viewer.