Index: src/os_unix.c ================================================================== --- src/os_unix.c +++ src/os_unix.c @@ -43,13 +43,10 @@ ** * Definitions of sqlite3_vfs objects for all locking methods ** plus implementations of sqlite3_os_init() and sqlite3_os_end(). */ #include "sqliteInt.h" #if SQLITE_OS_UNIX /* This file is used on unix only */ - -#include "btreeInt.h" /* Use by Apple extensions only */ - /* ** There are various methods for file locking used for concurrency ** control: ** @@ -101,14 +98,10 @@ #endif #if SQLITE_ENABLE_LOCKING_STYLE || OS_VXWORKS # include # include -# if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \ - (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000)) -# define HAVE_GETHOSTUUID 1 -# endif # if OS_VXWORKS # include # include # else # include @@ -1471,10 +1464,14 @@ unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close", pFile ? pFile->zPath : 0, lineno); } } +/* +** Set the pFile->lastErrno. Do this in a subroutine as that provides a convenient +** place to set a breakpoint. +*/ static void storeLastErrno(unixFile *pFile, int error){ pFile->lastErrno = error; } /* @@ -1669,11 +1666,11 @@ sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath); pFile->ctrlFlags |= UNIXFILE_WARNED; return; } if( fileHasMoved(pFile) ){ - sqlite3_log(SQLITE_WARNING, "file renamed while open: [%s]", pFile->zPath); + sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath); pFile->ctrlFlags |= UNIXFILE_WARNED; return; } } @@ -2382,19 +2379,19 @@ int rc = SQLITE_OK; unixFile *pFile = (unixFile *)id; unixEnterMutex(); /* unixFile.pInode is always valid here. Otherwise, a different close - ** routine (e.g. nolockClose()) would be called instead. - */ + ** routine (e.g. nolockClose()) would be called instead. + */ assert( pFile->pInode->nLock>0 || pFile->pInode->bProcessLock==0 ); if( ALWAYS(pFile->pInode) && pFile->pInode->nLock ){ /* If there are outstanding locks, do not actually close the file just - ** yet because that would clear those locks. Instead, add the file - ** descriptor to pInode->pUnused list. It will be automatically closed - ** when the last lock is cleared. - */ + ** yet because that would clear those locks. Instead, add the file + ** descriptor to pInode->pUnused list. It will be automatically closed + ** when the last lock is cleared. + */ setPendingFd(pFile); } releaseInodeInfo(pFile); rc = closeUnixFile(id); unixLeaveMutex(); @@ -3611,10 +3608,11 @@ return SQLITE_OK; }else if( got<0 ){ /* lastErrno set by seekAndRead */ return SQLITE_IOERR_READ; }else{ + storeLastErrno(pFile, 0); /* not a system error */ /* Unread parts of the buffer must be zero-filled */ memset(&((char*)pBuf)[got], 0, amt-got); return SQLITE_IOERR_SHORT_READ; } } @@ -3751,10 +3749,11 @@ if( amt>0 ){ if( wrote<0 && pFile->lastErrno!=ENOSPC ){ /* lastErrno set by seekAndWrite */ return SQLITE_IOERR_WRITE; }else{ + storeLastErrno(pFile, 0); /* not a system error */ return SQLITE_FULL; } } return SQLITE_OK; @@ -4156,11 +4155,11 @@ #if SQLITE_MAX_MMAP_SIZE>0 if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){ int rc; if( pFile->szChunk<=0 ){ if( robust_ftruncate(pFile->h, nByte) ){ - pFile->lastErrno = errno; + storeLastErrno(pFile, errno); return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath); } } rc = unixMapfile(pFile, nByte); @@ -4173,11 +4172,11 @@ #if (SQLITE_ENABLE_APPLE_SPI>0) && defined(__APPLE__) #include "sqlite3_private.h" #include -static int getDbPathForUnixFile(unixFile *pFile, char *dbPath); +static int proxyGetDbPathForUnixFile(unixFile *pFile, char *dbPath); #endif #if SQLITE_ENABLE_LOCKING_STYLE static int isProxyLockingMode(unixFile *); #endif @@ -4999,11 +4998,13 @@ unixEnterMutex(); pInode = pDbFd->pInode; pShmNode = pInode->pShmNode; if( pShmNode==0 ){ struct stat sStat; /* fstat() info for database file */ +#ifndef SQLITE_SHM_DIRECTORY const char *zBasePath = pDbFd->zPath; +#endif /* Call fstat() to figure out the permissions on the database file. If ** a new *-shm file is created, an attempt will be made to create it ** with the same permissions. */ @@ -5011,14 +5012,15 @@ storeLastErrno(pDbFd, errno); rc = SQLITE_IOERR_FSTAT; goto shm_open_err; } -#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE +#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE \ + && !defined(SQLITE_SHM_DIRECTORY) /* If pDbFd is configured with proxy locking mode, use the local - ** lock file path to determine the -shm file path - */ + ** lock file path to determine the -shm file path + */ if( isProxyLockingMode(pDbFd) ){ zBasePath = proxySharedMemoryBasePath(pDbFd); if( !zBasePath ){ rc = SQLITE_CANTOPEN_BKPT; goto shm_open_err; @@ -5444,11 +5446,11 @@ assert( pShmNode->nRef>0 ); pShmNode->nRef--; if( pShmNode->nRef==0 ){ if( deleteFlag && pShmNode->h>=0 ) { if (deleteFlag == 1) { - unlink(pShmNode->zFilename); + osUnlink(pShmNode->zFilename); } else if (deleteFlag == 2) { /* ftruncate(pShmNode->h, 32 * 1024); */ } } @@ -6564,11 +6566,11 @@ } unixLeaveMutex(); } #endif - pNew->lastErrno = 0; + storeLastErrno(pNew, 0); #if OS_VXWORKS if( rc!=SQLITE_OK ){ if( h>=0 ) robust_close(pNew, h, __LINE__); h = -1; osUnlink(zFilename); @@ -7498,13 +7500,14 @@ ** Using proxy locks ** ----------------- ** ** C APIs ** -** sqlite3_file_control(db, dbname, SQLITE_SET_LOCKPROXYFILE, +** sqlite3_file_control(db, dbname, SQLITE_FCNTL_SET_LOCKPROXYFILE, ** | ":auto:"); -** sqlite3_file_control(db, dbname, SQLITE_GET_LOCKPROXYFILE, &); +** sqlite3_file_control(db, dbname, SQLITE_FCNTL_GET_LOCKPROXYFILE, +** &); ** ** ** SQL pragmas ** ** PRAGMA [database.]lock_proxy_file= | :auto: @@ -7593,11 +7596,11 @@ ** ** As mentioned above, when compiled with SQLITE_PREFER_PROXY_LOCKING, ** setting the environment variable SQLITE_FORCE_PROXY_LOCKING to 1 will ** force proxy locking to be used for every database file opened, and 0 ** will force automatic proxy locking to be disabled for all database -** files (explicitly calling the SQLITE_SET_LOCKPROXYFILE pragma or +** files (explicitly calling the SQLITE_FCNTL_SET_LOCKPROXYFILE pragma or ** sqlite_file_control API is not affected by SQLITE_FORCE_PROXY_LOCKING). */ /* ** Proxy locking is only available on MacOSX @@ -7830,14 +7833,14 @@ ** bytes of writable memory. */ static int proxyGetHostID(unsigned char *pHostID, int *pError){ assert(PROXY_HOSTIDLEN == sizeof(uuid_t)); memset(pHostID, 0, PROXY_HOSTIDLEN); -#if HAVE_GETHOSTUUID +# if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \ + (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000)) { struct timespec timeout = {1, 0}; /* 1 sec timeout */ - if( gethostuuid(pHostID, &timeout) ){ int err = errno; if( pError ){ *pError = err; } @@ -8352,11 +8355,11 @@ ** is a string buffer at least MAXPATHLEN+1 characters in size. ** ** This routine find the filename associated with pFile and writes it ** int dbPath. */ -static int getDbPathForUnixFile(unixFile *pFile, char *dbPath){ +static int proxyGetDbPathForUnixFile(unixFile *pFile, char *dbPath){ #if defined(__APPLE__) if( pFile->pMethod == &afpIoMethods ){ /* afp style keeps a reference to the db path in the filePath field ** of the struct */ assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN ); @@ -8392,11 +8395,11 @@ int rc = SQLITE_OK; if( pFile->eFileLock!=NO_LOCK ){ return SQLITE_BUSY; } - getDbPathForUnixFile(pFile, dbPath); + proxyGetDbPathForUnixFile(pFile, dbPath); if( !path || path[0]=='\0' || !strcmp(path, ":auto:") ){ lockPath=NULL; }else{ lockPath=(char *)path; } @@ -8475,11 +8478,11 @@ ** This routine handles sqlite3_file_control() calls that are specific ** to proxy locking. */ static int proxyFileControl(sqlite3_file *id, int op, void *pArg){ switch( op ){ - case SQLITE_GET_LOCKPROXYFILE: { + case SQLITE_FCNTL_GET_LOCKPROXYFILE: { unixFile *pFile = (unixFile*)id; if( isProxyLockingMode(pFile) ){ proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext; proxyTakeConch(pFile); if( pCtx->lockProxyPath ){ @@ -8490,11 +8493,11 @@ } else { *(const char **)pArg = NULL; } return SQLITE_OK; } - case SQLITE_SET_LOCKPROXYFILE: { + case SQLITE_FCNTL_SET_LOCKPROXYFILE: { unixFile *pFile = (unixFile*)id; int rc = SQLITE_OK; int isProxyStyle = isProxyLockingMode(pFile); if( pArg==NULL || (const char *)pArg==0 ){ if( isProxyStyle ){