Ignore:
Timestamp:
Mar 18, 2014, 4:51:05 PM (11 years ago)
Author:
Silvan Scherrer
Message:

Samba 3.6: remove mutex sem and do it with a filelock

File:
1 edited

Legend:

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

    r846 r857  
    293293        }
    294294
    295 #ifdef __OS2__
    296         if (os2_crtSem(tdb, name, "tdb_open_ex") != 0)
    297                 goto fail;
    298 #endif
    299 
    300295        if ((tdb->fd = open(name, open_flags, mode)) == -1) {
    301296                TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_open_ex: could not open file %s: %s\n",
     
    314309                goto fail;      /* errno set by tdb_brlock */
    315310        }
     311
     312#ifdef __OS2__
     313        if (os2_crtActiveLock(tdb, name, 1, mode) != 0)
     314                goto fail;
     315#endif
    316316
    317317        /* we need to zero database if we are the only one with it open */
     
    476476
    477477#ifdef __OS2__
    478         DosCloseMutexSem(tdb->hActiveLock);
    479         tdb->hActiveLock = 0;
     478        close(tdb->hActiveLock);
     479        tdb->hActiveLock = -1;
    480480#endif
    481481        if (!tdb)
     
    548548
    549549#ifdef __OS2__
    550         DosCloseMutexSem(tdb->hActiveLock);
    551         tdb->hActiveLock = 0;
     550        close(tdb->hActiveLock);
     551        tdb->hActiveLock = -1;
    552552#endif
    553553
     
    620620
    621621#ifdef __OS2__
    622         DosCloseMutexSem(tdb->hActiveLock);
    623         tdb->hActiveLock = 0;
    624 
    625         if (os2_crtSem(tdb, tdb->name, "tdb_reopen") != 0)
     622        close(tdb->hActiveLock);
     623        tdb->hActiveLock = -1;
     624
     625        if (os2_crtActiveLock(tdb, tdb->name, 0, 0) != 0)
    626626                goto fail;
    627627#endif
     
    680680}
    681681#ifdef __OS2__
    682 int os2_crtSem(struct tdb_context *tdb, const char *name, const char *caller)
     682int os2_crtActiveLock(struct tdb_context *tdb, const char *name, const int truncate, const int mode)
    683683{
    684684        // name could be null, so handle it
     
    686686                return -1;
    687687
    688         char    szSem[_MAX_PATH];
    689         char    drive[_MAX_DRIVE], dir[_MAX_DIR];
    690         char    fname[_MAX_FNAME], ext[_MAX_EXT];
    691         APIRET  rc;
    692         // extract path info
    693         _splitpath(name, drive, dir, fname, ext);
    694         sprintf(szSem, "\\SEM32\\TDB_AL_%s%s%s", dir, fname, ext);
    695         rc = DosCreateMutexSem(szSem, &tdb->hActiveLock, 0, FALSE);
    696         if (rc == ERROR_DUPLICATE_NAME)
    697                 rc = DosOpenMutexSem(szSem, &tdb->hActiveLock);
    698         if (rc != NO_ERROR) {
    699                 TDB_LOG((tdb, TDB_DEBUG_ERROR, "os2_crtSem: cannot create sem32 %s (rc=%d) called from %s\n",
    700                         szSem, rc, caller));
     688        char activeLockName[_MAX_PATH];
     689        sprintf(activeLockName, "%s_AL", name);
     690        tdb->hActiveLock = open(activeLockName, tdb->open_flags, mode);
     691        if (tdb->hActiveLock == -1) {
     692                TDB_LOG((tdb, TDB_DEBUG_ERROR, "os2_crtSem: cannot create activeLock %s called from %s\n",
     693                        activeLockName, truncate?"tdb_open_ex":"tdb_reopen"));
    701694                errno = EINVAL;
    702695                return -1;
    703696        }
     697
     698        if (truncate) {
     699                if (lseek(tdb->hActiveLock, 0, SEEK_SET) == -1)
     700                        return -1;
     701
     702                if (ftruncate(tdb->hActiveLock, 0) == -1)
     703                        return -1;
     704
     705                tdb_write_all(tdb->hActiveLock, "used for active lock\n", 21);
     706        }
     707
    704708        return 0;
    705709}
Note: See TracChangeset for help on using the changeset viewer.