Ignore:
Timestamp:
Nov 25, 2013, 6:40:10 PM (12 years ago)
Author:
Silvan Scherrer
Message:

Samba 3.5: use fcntl and friends for locking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.5.x/lib/tdb/common/io.c

    r599 r836  
    9393        // YD we must upgrade read locks to write locks (exclusive), otherwise
    9494        // the owner (us) is not allowed to write to the file (different from unix)
    95         TDB_LOG((tdb, TDB_DEBUG_TRACE,"unlocking at %d len=%d before writing.\n", off, len));
    96         tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, 1);
    9795        // if a wider previous lock is in effect, we cannot write lock our segment
    9896        // (e.g. a lock_upgrade locks all the file), so we hope the previous lock
    9997        // is a write lock: do not wait for lock.
    100         tdb_brlock( tdb, off, F_WRLCK, F_SETLK, 0, len);
     98        int upgradeLockRC = tdb_brlock( tdb, off, F_WRLCK, F_SETLK, 0, len);
     99        TDB_LOG((tdb, TDB_DEBUG_TRACE,"upgrading lock at %d len=%d "
     100                "before writing %s (rc=%d).\n", off, len,
     101                 upgradeLockRC ? "was successfull":"failed", upgradeLockRC));
    101102#endif
    102103
     
    127128                                 len, off));
    128129
    129 #ifdef __OS2__ // remove our lock
    130                         tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len);
     130#ifdef __OS2__ // remove our lock, if upgrade succeded
     131                        if (upgradeLockRC == 0)
     132                                tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len);
    131133#endif
    132134                        return -1;
     
    134136        }
    135137
    136 #ifdef __OS2__ // remove our lock
    137         tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len);
     138#ifdef __OS2__ // remove our lock, if upgrade succeded
     139                        if (upgradeLockRC == 0)
     140                                tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len);
    138141#endif
    139142
Note: See TracChangeset for help on using the changeset viewer.