From: mistachkin Date: Thu, 10 Nov 2011 20:21:20 +0000 (+0000) Subject: In winAccess, save the Win32 last error value prior to invoking user logging callback... X-Git-Tag: mountain-lion~9^2~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2aef997cbdc535def641a4918dd0ca287ca72d9b;p=thirdparty%2Fsqlite.git In winAccess, save the Win32 last error value prior to invoking user logging callback. Also, explicitly pass the Win32 last error value to winLogError in order to keep it accurate. Fixes a problem reported on the mailing list. FossilOrigin-Name: 32ab365715e2c50f30aa2f92a323857b9d917bf6 --- diff --git a/manifest b/manifest index 53857bdc28..69f18e241a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Omit\san\sunnecessary\sSleep()\scall\sin\swindows\spending-lock\sretry\nlogic.\s\sEnhance\sthe\scomment\son\sthat\slogic\sto\sdiscourage\speople\nfrom\scopying\sit\sinto\sother\sVFSes. -D 2011-11-09T18:07:34.181 +C In\swinAccess,\ssave\sthe\sWin32\slast\serror\svalue\sprior\sto\sinvoking\suser\slogging\scallback.\s\sAlso,\sexplicitly\spass\sthe\sWin32\slast\serror\svalue\sto\swinLogError\sin\sorder\sto\skeep\sit\saccurate.\s\sFixes\sa\sproblem\sreported\son\sthe\smailing\slist. +D 2011-11-10T20:21:20.308 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -167,7 +167,7 @@ F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440 F src/os_unix.c 4fbb91726165e105c1679a2660f49a3f4c376e4f -F src/os_win.c 6749a95cfe4bf00b71716515ca1c2601aa212ef8 +F src/os_win.c a9190cb70e5071776e0064f7a04778c594c2afad F src/pager.c db33d4bf1e3e019c34c220971cc6c3aa07c30f54 F src/pager.h 9f81b08efb06db4ba8be69446e10b005c351373d F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58 @@ -974,7 +974,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P a210695abcfa5cb04279edfd04824d881b7c4ada -R e1dcb4cfde514f4d6d711be7740004c1 -U drh -Z 8231b98b427b17224b8ab6c5f9a53e24 +P 0c951a970436725b6bbd64568de500f7a4e6460b +R 07fcb0ebb49fcaa5a3b1285d87c90ade +U mistachkin +Z 984e599e94c8add22fe67965d6d580c6 diff --git a/manifest.uuid b/manifest.uuid index 06b8ed2350..cee874f887 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0c951a970436725b6bbd64568de500f7a4e6460b \ No newline at end of file +32ab365715e2c50f30aa2f92a323857b9d917bf6 \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 71c5248f70..e8ea45583f 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -630,16 +630,16 @@ static int getLastErrorMsg(int nBuf, char *zBuf){ ** The two subsequent arguments should be the name of the OS function that ** failed and the the associated file-system path, if any. */ -#define winLogError(a,b,c) winLogErrorAtLine(a,b,c,__LINE__) +#define winLogError(a,b,c,d) winLogErrorAtLine(a,b,c,d,__LINE__) static int winLogErrorAtLine( int errcode, /* SQLite error code */ + DWORD lastErrno, /* Win32 last error */ const char *zFunc, /* Name of OS function that failed */ const char *zPath, /* File path associated with error */ int iLine /* Source line number where error occurred */ ){ char zMsg[500]; /* Human readable error text */ int i; /* Loop counter */ - DWORD iErrno = GetLastError(); /* Error code */ zMsg[0] = 0; getLastErrorMsg(sizeof(zMsg), zMsg); @@ -649,7 +649,7 @@ static int winLogErrorAtLine( zMsg[i] = 0; sqlite3_log(errcode, "os_win.c:%d: (%d) %s(%s) - %s", - iLine, iErrno, zFunc, zPath, zMsg + iLine, lastErrno, zFunc, zPath, zMsg ); return errcode; @@ -780,7 +780,7 @@ static BOOL winceCreateLock(const char *zFilename, winFile *pFile){ pFile->hMutex = CreateMutexW(NULL, FALSE, zName); if (!pFile->hMutex){ pFile->lastErrno = GetLastError(); - winLogError(SQLITE_ERROR, "winceCreateLock1", zFilename); + winLogError(SQLITE_ERROR, pFile->lastErrno, "winceCreateLock1", zFilename); free(zName); return FALSE; } @@ -812,7 +812,8 @@ static BOOL winceCreateLock(const char *zFilename, winFile *pFile){ /* If mapping failed, close the shared memory handle and erase it */ if (!pFile->shared){ pFile->lastErrno = GetLastError(); - winLogError(SQLITE_ERROR, "winceCreateLock2", zFilename); + winLogError(SQLITE_ERROR, pFile->lastErrno, + "winceCreateLock2", zFilename); CloseHandle(pFile->hShared); pFile->hShared = NULL; } @@ -1058,7 +1059,8 @@ static int seekWinFile(winFile *pFile, sqlite3_int64 iOffset){ dwRet = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN); if( (dwRet==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR) ){ pFile->lastErrno = GetLastError(); - winLogError(SQLITE_IOERR_SEEK, "seekWinFile", pFile->zPath); + winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno, + "seekWinFile", pFile->zPath); return 1; } @@ -1105,7 +1107,8 @@ static int winClose(sqlite3_file *id){ OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed")); OpenCounter(-1); return rc ? SQLITE_OK - : winLogError(SQLITE_IOERR_CLOSE, "winClose", pFile->zPath); + : winLogError(SQLITE_IOERR_CLOSE, GetLastError(), + "winClose", pFile->zPath); } /* @@ -1133,7 +1136,8 @@ static int winRead( while( !ReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ if( retryIoerr(&nRetry) ) continue; pFile->lastErrno = GetLastError(); - return winLogError(SQLITE_IOERR_READ, "winRead", pFile->zPath); + return winLogError(SQLITE_IOERR_READ, pFile->lastErrno, + "winRead", pFile->zPath); } logIoerr(nRetry); if( nRead<(DWORD)amt ){ @@ -1192,7 +1196,8 @@ static int winWrite( || ( pFile->lastErrno==ERROR_DISK_FULL )){ return SQLITE_FULL; } - return winLogError(SQLITE_IOERR_WRITE, "winWrite", pFile->zPath); + return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno, + "winWrite", pFile->zPath); }else{ logIoerr(nRetry); } @@ -1222,10 +1227,12 @@ static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){ /* SetEndOfFile() returns non-zero when successful, or zero when it fails. */ if( seekWinFile(pFile, nByte) ){ - rc = winLogError(SQLITE_IOERR_TRUNCATE, "winTruncate1", pFile->zPath); + rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno, + "winTruncate1", pFile->zPath); }else if( 0==SetEndOfFile(pFile->h) ){ pFile->lastErrno = GetLastError(); - rc = winLogError(SQLITE_IOERR_TRUNCATE, "winTruncate2", pFile->zPath); + rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno, + "winTruncate2", pFile->zPath); } OSTRACE(("TRUNCATE %d %lld %s\n", pFile->h, nByte, rc ? "failed" : "ok")); @@ -1296,7 +1303,8 @@ static int winSync(sqlite3_file *id, int flags){ return SQLITE_OK; }else{ pFile->lastErrno = GetLastError(); - return winLogError(SQLITE_IOERR_FSYNC, "winSync", pFile->zPath); + return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno, + "winSync", pFile->zPath); } #endif } @@ -1317,7 +1325,8 @@ static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){ && ((error = GetLastError()) != NO_ERROR) ) { pFile->lastErrno = error; - return winLogError(SQLITE_IOERR_FSTAT, "winFileSize", pFile->zPath); + return winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno, + "winFileSize", pFile->zPath); } *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits; return SQLITE_OK; @@ -1377,7 +1386,8 @@ static int unlockReadLock(winFile *pFile){ } if( res==0 && GetLastError()!=ERROR_NOT_LOCKED ){ pFile->lastErrno = GetLastError(); - winLogError(SQLITE_IOERR_UNLOCK, "unlockReadLock", pFile->zPath); + winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno, + "unlockReadLock", pFile->zPath); } return res; } @@ -1580,7 +1590,8 @@ static int winUnlock(sqlite3_file *id, int locktype){ if( locktype==SHARED_LOCK && !getReadLock(pFile) ){ /* This should never happen. We should always be able to ** reacquire the read lock */ - rc = winLogError(SQLITE_IOERR_UNLOCK, "winUnlock", pFile->zPath); + rc = winLogError(SQLITE_IOERR_UNLOCK, GetLastError(), + "winUnlock", pFile->zPath); } } if( type>=RESERVED_LOCK ){ @@ -1971,7 +1982,8 @@ static int winOpenSharedMemory(winFile *pDbFd){ if( winShmSystemLock(pShmNode, _SHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){ rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0); if( rc!=SQLITE_OK ){ - rc = winLogError(SQLITE_IOERR_SHMOPEN, "winOpenShm", pDbFd->zPath); + rc = winLogError(SQLITE_IOERR_SHMOPEN, GetLastError(), + "winOpenShm", pDbFd->zPath); } } if( rc==SQLITE_OK ){ @@ -2230,7 +2242,8 @@ static int winShmMap( */ rc = winFileSize((sqlite3_file *)&pShmNode->hFile, &sz); if( rc!=SQLITE_OK ){ - rc = winLogError(SQLITE_IOERR_SHMSIZE, "winShmMap1", pDbFd->zPath); + rc = winLogError(SQLITE_IOERR_SHMSIZE, GetLastError(), + "winShmMap1", pDbFd->zPath); goto shmpage_out; } @@ -2244,7 +2257,8 @@ static int winShmMap( if( !isWrite ) goto shmpage_out; rc = winTruncate((sqlite3_file *)&pShmNode->hFile, nByte); if( rc!=SQLITE_OK ){ - rc = winLogError(SQLITE_IOERR_SHMSIZE, "winShmMap2", pDbFd->zPath); + rc = winLogError(SQLITE_IOERR_SHMSIZE, GetLastError(), + "winShmMap2", pDbFd->zPath); goto shmpage_out; } } @@ -2281,7 +2295,8 @@ static int winShmMap( } if( !pMap ){ pShmNode->lastErrno = GetLastError(); - rc = winLogError(SQLITE_IOERR_SHMMAP, "winShmMap3", pDbFd->zPath); + rc = winLogError(SQLITE_IOERR_SHMMAP, pShmNode->lastErrno, + "winShmMap3", pDbFd->zPath); if( hMap ) CloseHandle(hMap); goto shmpage_out; } @@ -2615,7 +2630,7 @@ static int winOpen( if( h==INVALID_HANDLE_VALUE ){ pFile->lastErrno = GetLastError(); - winLogError(SQLITE_CANTOPEN, "winOpen", zUtf8Name); + winLogError(SQLITE_CANTOPEN, pFile->lastErrno, "winOpen", zUtf8Name); free(zConverted); if( isReadWrite && !isExclusive ){ return winOpen(pVfs, zName, id, @@ -2708,7 +2723,8 @@ static int winDelete( #endif } if( rc ){ - rc = winLogError(SQLITE_IOERR_DELETE, "winDelete", zFilename); + rc = winLogError(SQLITE_IOERR_DELETE, GetLastError(), + "winDelete", zFilename); }else{ logIoerr(cnt); } @@ -2755,9 +2771,10 @@ static int winAccess( attr = sAttrData.dwFileAttributes; } }else{ + DWORD lastErrno = GetLastError(); logIoerr(cnt); - if( GetLastError()!=ERROR_FILE_NOT_FOUND ){ - winLogError(SQLITE_IOERR_ACCESS, "winAccess", zFilename); + if( lastErrno!=ERROR_FILE_NOT_FOUND ){ + winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", zFilename); free(zConverted); return SQLITE_IOERR_ACCESS; }else{