/ Check-in [8d1b5c3a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Allow the unlink() system call to be overridden in os_unix.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8d1b5c3ac027ac00d57a250aad45230a09645617
User & Date: drh 2011-08-08 23:18:05
Context
2011-08-08
23:48
In os_unix.c, do not open the directory containing the database file when the database file is opened. Instead, wait until time to fsync() the directory. And do not report an error if the open fails, since some systems (Ex: AIX and a chromium sandbox) are unable to open and fsync directories. check-in: 713b1b7d user: drh tags: trunk
23:18
Allow the unlink() system call to be overridden in os_unix.c. check-in: 8d1b5c3a user: drh tags: trunk
2011-08-07
01:31
Remove relevant elements from the sqlite_stat2 table when doing a DROP INDEX or DROP TABLE. check-in: 3c8f97ae user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

   390    390   #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
   391    391     { "fallocate",    (sqlite3_syscall_ptr)posix_fallocate,  0 },
   392    392   #else
   393    393     { "fallocate",    (sqlite3_syscall_ptr)0,                0 },
   394    394   #endif
   395    395   #define osFallocate ((int(*)(int,off_t,off_t))aSyscall[15].pCurrent)
   396    396   
          397  +  { "unlink",       (sqlite3_syscall_ptr)unlink,           0 },
          398  +#define osUnlink    ((int(*)(const char*))aSyscall[16].pCurrent)
          399  +
   397    400   }; /* End of the overrideable system calls */
   398    401   
   399    402   /*
   400    403   ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
   401    404   ** "unix" VFSes.  Return SQLITE_OK opon successfully updating the
   402    405   ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
   403    406   ** system call named zName.
................................................................................
  1757   1760     if( pFile->h>=0 ){
  1758   1761       robust_close(pFile, pFile->h, __LINE__);
  1759   1762       pFile->h = -1;
  1760   1763     }
  1761   1764   #if OS_VXWORKS
  1762   1765     if( pFile->pId ){
  1763   1766       if( pFile->isDelete ){
  1764         -      unlink(pFile->pId->zCanonicalName);
         1767  +      osUnlink(pFile->pId->zCanonicalName);
  1765   1768       }
  1766   1769       vxworksReleaseFileId(pFile->pId);
  1767   1770       pFile->pId = 0;
  1768   1771     }
  1769   1772   #endif
  1770   1773     OSTRACE(("CLOSE   %-3d\n", pFile->h));
  1771   1774     OpenCounter(-1);
................................................................................
  2006   2009     if( eFileLock==SHARED_LOCK ){
  2007   2010       pFile->eFileLock = SHARED_LOCK;
  2008   2011       return SQLITE_OK;
  2009   2012     }
  2010   2013     
  2011   2014     /* To fully unlock the database, delete the lock file */
  2012   2015     assert( eFileLock==NO_LOCK );
  2013         -  if( unlink(zLockFile) ){
         2016  +  if( osUnlink(zLockFile) ){
  2014   2017       int rc = 0;
  2015   2018       int tErrno = errno;
  2016   2019       if( ENOENT != tErrno ){
  2017   2020         rc = SQLITE_IOERR_UNLOCK;
  2018   2021       }
  2019   2022       if( IS_LOCK_ERROR(rc) ){
  2020   2023         pFile->lastErrno = tErrno;
................................................................................
  4158   4161   
  4159   4162     /* If pShmNode->nRef has reached 0, then close the underlying
  4160   4163     ** shared-memory file, too */
  4161   4164     unixEnterMutex();
  4162   4165     assert( pShmNode->nRef>0 );
  4163   4166     pShmNode->nRef--;
  4164   4167     if( pShmNode->nRef==0 ){
  4165         -    if( deleteFlag && pShmNode->h>=0 ) unlink(pShmNode->zFilename);
         4168  +    if( deleteFlag && pShmNode->h>=0 ) osUnlink(pShmNode->zFilename);
  4166   4169       unixShmPurge(pDbFd);
  4167   4170     }
  4168   4171     unixLeaveMutex();
  4169   4172   
  4170   4173     return SQLITE_OK;
  4171   4174   }
  4172   4175   
................................................................................
  4638   4641   #endif
  4639   4642     
  4640   4643     pNew->lastErrno = 0;
  4641   4644   #if OS_VXWORKS
  4642   4645     if( rc!=SQLITE_OK ){
  4643   4646       if( h>=0 ) robust_close(pNew, h, __LINE__);
  4644   4647       h = -1;
  4645         -    unlink(zFilename);
         4648  +    osUnlink(zFilename);
  4646   4649       isDelete = 0;
  4647   4650     }
  4648   4651     pNew->isDelete = isDelete;
  4649   4652   #endif
  4650   4653     if( rc!=SQLITE_OK ){
  4651   4654       if( dirfd>=0 ) robust_close(pNew, dirfd, __LINE__);
  4652   4655       if( h>=0 ) robust_close(pNew, h, __LINE__);
................................................................................
  5045   5048       p->pUnused->flags = flags;
  5046   5049     }
  5047   5050   
  5048   5051     if( isDelete ){
  5049   5052   #if OS_VXWORKS
  5050   5053       zPath = zName;
  5051   5054   #else
  5052         -    unlink(zName);
         5055  +    osUnlink(zName);
  5053   5056   #endif
  5054   5057     }
  5055   5058   #if SQLITE_ENABLE_LOCKING_STYLE
  5056   5059     else{
  5057   5060       p->openFlags = openFlags;
  5058   5061     }
  5059   5062   #endif
................................................................................
  5160   5163     sqlite3_vfs *NotUsed,     /* VFS containing this as the xDelete method */
  5161   5164     const char *zPath,        /* Name of file to be deleted */
  5162   5165     int dirSync               /* If true, fsync() directory after deleting file */
  5163   5166   ){
  5164   5167     int rc = SQLITE_OK;
  5165   5168     UNUSED_PARAMETER(NotUsed);
  5166   5169     SimulateIOError(return SQLITE_IOERR_DELETE);
  5167         -  if( unlink(zPath)==(-1) && errno!=ENOENT ){
         5170  +  if( osUnlink(zPath)==(-1) && errno!=ENOENT ){
  5168   5171       return unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath);
  5169   5172     }
  5170   5173   #ifndef SQLITE_DISABLE_DIRSYNC
  5171   5174     if( dirSync ){
  5172   5175       int fd;
  5173   5176       rc = openDirectory(zPath, &fd);
  5174   5177       if( rc==SQLITE_OK ){
................................................................................
  5917   5920     robust_close(pFile, conchFile->h, __LINE__);
  5918   5921     conchFile->h = fd;
  5919   5922     conchFile->openFlags = O_RDWR | O_CREAT;
  5920   5923   
  5921   5924   end_breaklock:
  5922   5925     if( rc ){
  5923   5926       if( fd>=0 ){
  5924         -      unlink(tPath);
         5927  +      osUnlink(tPath);
  5925   5928         robust_close(pFile, fd, __LINE__);
  5926   5929       }
  5927   5930       fprintf(stderr, "failed to break stale lock on %s, %s\n", cPath, errmsg);
  5928   5931     }
  5929   5932     return rc;
  5930   5933   }
  5931   5934   
................................................................................
  6740   6743       UNIXVFS("unix-proxy",    proxyIoFinder ),
  6741   6744   #endif
  6742   6745     };
  6743   6746     unsigned int i;          /* Loop counter */
  6744   6747   
  6745   6748     /* Double-check that the aSyscall[] array has been constructed
  6746   6749     ** correctly.  See ticket [bb3a86e890c8e96ab] */
  6747         -  assert( ArraySize(aSyscall)==16 );
         6750  +  assert( ArraySize(aSyscall)==17 );
  6748   6751   
  6749   6752     /* Register all VFSes defined in the aVfs[] array */
  6750   6753     for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
  6751   6754       sqlite3_vfs_register(&aVfs[i], i==0);
  6752   6755     }
  6753   6756     return SQLITE_OK; 
  6754   6757   }

Changes to test/syscall.test.

    55     55   
    56     56   #-------------------------------------------------------------------------
    57     57   # Tests for the xNextSystemCall method.
    58     58   #
    59     59   foreach s {
    60     60       open close access getcwd stat fstat ftruncate
    61     61       fcntl read pread write pwrite fchmod fallocate
    62         -    pread64 pwrite64
           62  +    pread64 pwrite64 unlink
    63     63   } {
    64     64     if {[test_syscall exists $s]} {lappend syscall_list $s}
    65     65   }
    66     66   do_test 3.1 { lsort [test_syscall list] } [lsort $syscall_list]
    67     67   
    68     68   #-------------------------------------------------------------------------
    69     69   # This test verifies that if a call to open() fails and errno is set to