]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Have the UNIX VFS issue warnings via sqlite3_log() if a database file is
authordrh <drh@noemail.net>
Thu, 11 Apr 2013 01:16:15 +0000 (01:16 +0000)
committerdrh <drh@noemail.net>
Thu, 11 Apr 2013 01:16:15 +0000 (01:16 +0000)
renamed or unlinked or linked to more than one name while the file is open.

FossilOrigin-Name: e238dcf9189c029fbdcf89339e21d9cdd8fbf2c5

manifest
manifest.uuid
src/os_unix.c

index 6d3e751585675d3dfeb0206227cabf65db50543b..672a0594059149715b28e3b87bb744ae18b2340c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Enhance\smulti-process\stester\sintegration\swith\sthe\sWin32\sAPI.
-D 2013-04-11T00:09:44.820
+C Have\sthe\sUNIX\sVFS\sissue\swarnings\svia\ssqlite3_log()\sif\sa\sdatabase\sfile\sis\nrenamed\sor\sunlinked\sor\slinked\sto\smore\sthan\sone\sname\swhile\sthe\sfile\sis\sopen.
+D 2013-04-11T01:16:15.249
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 3dd3fcb87b70c78d99b2c8a03e44ec86d6ca9ce2
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -166,7 +166,7 @@ F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30
 F src/os.c ca679b293a6233327e418fd1dde2cd5db3e90932
 F src/os.h ae08bcc5f6ec6b339f4a2adf3931bb88cc14c3e4
 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
-F src/os_unix.c a6e9caadd8956a39153d1bd920e459211a281388
+F src/os_unix.c 5707fcb125f043e2d3376ea862e8ec83633c5e0e
 F src/os_win.c 3aec291c40048653c00a153fee96d3a442ab85ee
 F src/pager.c 28f45e60d9a173368872d6e688e7a848c3926344
 F src/pager.h 5cb78b8e1adfd5451e600be7719f5a99d87ac3b1
@@ -1050,7 +1050,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P be7d2c5482c41baf000d7fb5dccc31b974e91064
-R 255ee63faf4906e3f01e118bd1c7af53
-U mistachkin
-Z 56dc3349791505b3e20ff09949e0bcd7
+P 0fdc743583c67a3a017b9ad812c62a5104b9aee7
+R 6358d94b9e9fcf447041dc89384ceff9
+U drh
+Z 7f7d7e8aee1747123050111170b5d1bc
index 557333d3d0e7a47b9e120b2a5ccda3cbe902b570..784964e39bf16e2fafc0b203b54a846a60b76db1 100644 (file)
@@ -1 +1 @@
-0fdc743583c67a3a017b9ad812c62a5104b9aee7
\ No newline at end of file
+e238dcf9189c029fbdcf89339e21d9cdd8fbf2c5
\ No newline at end of file
index a65f894eb8c654395eb83ce26a707dd487a68601..778575f7b191599f39b18d034a91cc50a64fe484 100644 (file)
@@ -280,6 +280,7 @@ struct unixFile {
 #define UNIXFILE_DELETE      0x20     /* Delete on close */
 #define UNIXFILE_URI         0x40     /* Filename might have query parameters */
 #define UNIXFILE_NOLOCK      0x80     /* Do no file locking */
+#define UNIXFILE_WARNED    0x0100     /* verifyDbFile() warnings have been issued */
 
 /*
 ** Include code that is common to all os_*.c files
@@ -799,7 +800,6 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
 }
 
 
-
 /******************************************************************************
 ****************** Begin Unique File ID Utility Used By VxWorks ***************
 **
@@ -1300,6 +1300,50 @@ static int findInodeInfo(
 }
 
 
+/*
+** Check a unixFile that is a database.  Verify the following:
+**
+** (1) There is exactly one hard link on the file
+** (2) The file is not a symbolic link
+** (3) The file has not been renamed or unlinked
+**
+** Issue sqlite3_log(SQLITE_WARNING,...) messages if anything is not right.
+*/
+static void verifyDbFile(unixFile *pFile){
+  struct stat buf;
+  int rc;
+  if( pFile->ctrlFlags & UNIXFILE_WARNED ){
+    /* One or more of the following warnings have already been issued.  Do not
+    ** repeat them so as not to clutter the error log */
+    return;
+  }
+  rc = osFstat(pFile->h, &buf);
+  if( rc!=0 ){
+    sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath);
+    pFile->ctrlFlags |= UNIXFILE_WARNED;
+    return;
+  }
+  if( buf.st_nlink==0 && (pFile->ctrlFlags & UNIXFILE_DELETE)==0 ){
+    sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath);
+    pFile->ctrlFlags |= UNIXFILE_WARNED;
+    return;
+  }
+  if( buf.st_nlink>1 ){
+    sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
+    pFile->ctrlFlags |= UNIXFILE_WARNED;
+    return;
+  }
+  if( pFile->pInode!=0
+   && ((rc = osStat(pFile->zPath, &buf))!=0
+       || buf.st_ino!=pFile->pInode->fileId.ino)
+  ){
+    sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
+    pFile->ctrlFlags |= UNIXFILE_WARNED;
+    return;
+  }
+}
+
+
 /*
 ** This routine checks if there is a RESERVED lock held on the specified
 ** file by this or any other process. If such a lock is held, set *pResOut
@@ -1876,6 +1920,7 @@ static int closeUnixFile(sqlite3_file *id){
 static int unixClose(sqlite3_file *id){
   int rc = SQLITE_OK;
   unixFile *pFile = (unixFile *)id;
+  verifyDbFile(pFile);
   unixUnlock(id, NO_LOCK);
   unixEnterMutex();
 
@@ -4539,6 +4584,7 @@ static void unixUnmapfile(unixFile *pFd){
 #endif
 }
 
+#ifndef SQLITE_DISABLE_MMAP
 /*
 ** Return the system page size.
 */
@@ -4551,6 +4597,7 @@ static int unixGetPagesize(void){
   return (int)sysconf(_SC_PAGESIZE);
 #endif
 }
+#endif /* SQLITE_DISABLE_MMAP */
 
 #ifndef SQLITE_DISABLE_MMAP
 /*
@@ -4656,10 +4703,10 @@ static void unixRemapfile(
 ** code otherwise.
 */
 static int unixMapfile(unixFile *pFd, i64 nByte){
+#ifndef SQLITE_DISABLE_MMAP
   i64 nMap = nByte;
   int rc;
 
-#ifndef SQLITE_DISABLE_MMAP
   assert( nMap>=0 || pFd->nFetchOut==0 );
   if( pFd->nFetchOut>0 ) return SQLITE_OK;
 
@@ -4700,7 +4747,9 @@ static int unixMapfile(unixFile *pFd, i64 nByte){
 ** release the reference by calling unixUnfetch().
 */
 static int unixFetch(sqlite3_file *fd, i64 iOff, int nAmt, void **pp){
+#ifndef SQLITE_DISABLE_MMAP
   unixFile *pFd = (unixFile *)fd;   /* The underlying database file */
+#endif
   *pp = 0;
 
 #ifndef SQLITE_DISABLE_MMAP
@@ -5222,6 +5271,7 @@ static int fillInUnixFile(
   }else{
     pNew->pMethod = pLockingStyle;
     OpenCounter(+1);
+    verifyDbFile(pNew);
   }
   return rc;
 }