1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Merge the syscall-override changes into trunk.

FossilOrigin-Name: 36d79e6f54cdc4129c6e6366a49722e2cf1cccbd
This commit is contained in:
drh
2011-03-08 16:39:29 +00:00
5 changed files with 284 additions and 94 deletions

View File

@@ -1,8 +1,8 @@
-----BEGIN PGP SIGNED MESSAGE----- -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 Hash: SHA1
C Unix\serrno\sinteger\scan\svary\sfrom\sone\ssystem\sto\sthe\snext.\s\sSo\sdo\snot\ndepend\son\sspecific\serrno\svalues\sin\stest\scases. C Merge\sthe\ssyscall-override\schanges\sinto\strunk.
D 2011-03-08T14:05:07.476 D 2011-03-08T16:39:29.275
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -165,8 +165,8 @@ F src/os.c 22ac61d06e72a0dac900400147333b07b13d8e1d
F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9 F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9
F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f
F src/os_os2.c 2e452c9f2ca507623ad351c33a8a8b27849b1863 F src/os_os2.c 2e452c9f2ca507623ad351c33a8a8b27849b1863
F src/os_unix.c 67f9a304641f126f5f7326cd452c2df3d9a4d512 F src/os_unix.c 58fe8845678f6a4e30ed6988c5df7327bc7bd69b
F src/os_win.c 9abdcdd925416d854eabb0996c96debd92abfef5 F src/os_win.c 24d72407a90551969744cf9bcbb1b4c72c5fa845
F src/pager.c 6aa906b60a59664ba58d3f746164bb010d407ce1 F src/pager.c 6aa906b60a59664ba58d3f746164bb010d407ce1
F src/pager.h 3f8c783de1d4706b40b1ac15b64f5f896bcc78d1 F src/pager.h 3f8c783de1d4706b40b1ac15b64f5f896bcc78d1
F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58 F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58
@@ -181,7 +181,7 @@ F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706
F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
F src/select.c d24406c45dd2442eb2eeaac413439066b149c944 F src/select.c d24406c45dd2442eb2eeaac413439066b149c944
F src/shell.c 649c51979812f77f97507024a4cea480c6862b8b F src/shell.c 649c51979812f77f97507024a4cea480c6862b8b
F src/sqlite.h.in ccb23cc9378874c7c72682b739f311474a80848d F src/sqlite.h.in 82274d7f4440b99a80d8cc4f077547fd0b596017
F src/sqlite3ext.h c90bd5507099f62043832d73f6425d8d5c5da754 F src/sqlite3ext.h c90bd5507099f62043832d73f6425d8d5c5da754
F src/sqliteInt.h 2cea3e47997e3f4d9b4f1ce62f99c35be1b5a586 F src/sqliteInt.h 2cea3e47997e3f4d9b4f1ce62f99c35be1b5a586
F src/sqliteLimit.h a17dcd3fb775d63b64a43a55c54cb282f9726f44 F src/sqliteLimit.h a17dcd3fb775d63b64a43a55c54cb282f9726f44
@@ -914,14 +914,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P c829868aa2254c5e2268cdb803462cc6ec5cb71e P ddb747d33a004c7fe532a661e879ccba68c79c59 a7d176b27cd73791d45eb3a31df78187ae10ce20
R 8e95dcc047fadda9627799dfff537929 R f6d9df8153eea975bd4c019ada4938a6
U drh U drh
Z 37a2076ebac96d581357fbed13c5025e Z a4115902c8e36dff16feb9c6102d7895
-----BEGIN PGP SIGNATURE----- -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux) Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFNdjeWoxKgR168RlERAqe0AJ0VGxcf5Ph+FO32DM9O7OJzqJKoKgCgi6Pc iD8DBQFNdlvEoxKgR168RlERAqctAJ0QkDzaXcGb8cYDn6Z1juSfygSdZgCcCoJg
n0W6zXncDy5KyrZP5XyTfdc= HYxK6HQIevTUFNLB5q3ux8E=
=lDvF =p3yO
-----END PGP SIGNATURE----- -----END PGP SIGNATURE-----

View File

@@ -1 +1 @@
ddb747d33a004c7fe532a661e879ccba68c79c59 36d79e6f54cdc4129c6e6366a49722e2cf1cccbd

View File

@@ -270,16 +270,6 @@ struct unixFile {
# define O_BINARY 0 # define O_BINARY 0
#endif #endif
/*
** The DJGPP compiler environment looks mostly like Unix, but it
** lacks the fcntl() system call. So redefine fcntl() to be something
** that always succeeds. This means that locking does not occur under
** DJGPP. But it is DOS - what did you expect?
*/
#ifdef __DJGPP__
# define fcntl(A,B,C) 0
#endif
/* /*
** The threadid macro resolves to the thread-id or to 0. Used for ** The threadid macro resolves to the thread-id or to 0. Used for
** testing and debugging only. ** testing and debugging only.
@@ -290,6 +280,184 @@ struct unixFile {
#define threadid 0 #define threadid 0
#endif #endif
/*
** Many system calls are accessed through pointer-to-functions so that
** they may be overridden at runtime to facilitate fault injection during
** testing and sandboxing. The following array holds the names and pointers
** to all overrideable system calls.
*/
static struct unix_syscall {
const char *zName; /* Name of the sytem call */
void *pCurrent; /* Current value of the system call */
void *pDefault; /* Default value */
} aSyscall[] = {
{ "open", (void*)open, 0 },
#define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent)
{ "close", (void*)close, 0 },
#define osClose ((int(*)(int))aSyscall[1].pCurrent)
{ "access", (void*)access, 0 },
#define osAccess ((int(*)(const char*,int))aSyscall[2].pCurrent)
{ "getcwd", (void*)getcwd, 0 },
#define osGetcwd ((char*(*)(char*,size_t))aSyscall[3].pCurrent)
{ "stat", (void*)stat, 0 },
#define osStat ((int(*)(const char*,struct stat*))aSyscall[4].pCurrent)
/*
** The DJGPP compiler environment looks mostly like Unix, but it
** lacks the fcntl() system call. So redefine fcntl() to be something
** that always succeeds. This means that locking does not occur under
** DJGPP. But it is DOS - what did you expect?
*/
#ifdef __DJGPP__
{ "fstat", 0, 0 },
#define osFstat(a,b,c) 0
#else
{ "fstat", (void*)fstat, 0 },
#define osFstat ((int(*)(int,struct stat*))aSyscall[5].pCurrent)
#endif
{ "ftruncate", (void*)ftruncate, 0 },
#define osFtruncate ((int(*)(int,off_t))aSyscall[6].pCurrent)
{ "fcntl", (void*)fcntl, 0 },
#define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent)
{ "read", (void*)read, 0 },
#define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent)
#if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE)
{ "pread", (void*)pread, 0 },
#else
{ "pread", (void*)0, 0 },
#endif
#define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent)
#if defined(USE_PREAD64)
{ "pread64", (void*)pread64, 0 },
#else
{ "pread64", (void*)0, 0 },
#endif
#define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
{ "write", (void*)write, 0 },
#define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
#if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE)
{ "pwrite", (void*)pwrite, 0 },
#else
{ "pwrite", (void*)0, 0 },
#endif
#define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\
aSyscall[12].pCurrent)
#if defined(USE_PREAD64)
{ "pwrite64", (void*)pwrite64, 0 },
#else
{ "pwrite64", (void*)0, 0 },
#endif
#define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\
aSyscall[13].pCurrent)
{ "fchmod", (void*)fchmod, 0 },
#define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
{ "fallocate", (void*)posix_fallocate, 0 },
#else
{ "fallocate", (void*)0, 0 },
#endif
#define osFallocate ((int(*)(int,off_t,off_t)aSyscall[15].pCurrent)
}; /* End of the overrideable system calls */
/*
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
** "unix" VFSes. Return SQLITE_OK opon successfully updating the
** system call pointer, or SQLITE_NOTFOUND if there is no configurable
** system call named zName.
*/
static int unixSetSystemCall(
sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */
const char *zName, /* Name of system call to override */
void *pNewFunc /* Pointer to new system call value */
){
int i;
int rc = SQLITE_NOTFOUND;
if( zName==0 ){
/* If no zName is given, restore all system calls to their default
** settings and return NULL
*/
for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
if( aSyscall[i].pDefault ){
aSyscall[i].pCurrent = aSyscall[i].pDefault;
rc = SQLITE_OK;
}
}
}else{
/* If zName is specified, operate on only the one system call
** specified.
*/
for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
if( strcmp(zName, aSyscall[i].zName)==0 ){
if( aSyscall[i].pDefault==0 ){
aSyscall[i].pDefault = aSyscall[i].pCurrent;
}
rc = SQLITE_OK;
if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault;
aSyscall[i].pCurrent = pNewFunc;
break;
}
}
}
return rc;
}
/*
** Return the value of a system call. Return NULL if zName is not a
** recognized system call name. NULL is also returned if the system call
** is currently undefined.
*/
static void *unixGetSystemCall(sqlite3_vfs *pNotUsed, const char *zName){
int i;
for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent;
}
return 0;
}
/*
** Return the name of the first system call after zName. If zName==NULL
** then return the name of the first system call. Return NULL if zName
** is the last system call or if zName is not the name of a valid
** system call.
*/
static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){
int i;
if( zName==0 ){
i = -1;
}else{
for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0])-1; i++){
if( strcmp(zName, aSyscall[0].zName)==0 ) break;
}
}
for(i++; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
if( aSyscall[0].pCurrent!=0 ) return aSyscall[0].zName;
}
return 0;
}
/*
** Retry open() calls that fail due to EINTR
*/
static int robust_open(const char *z, int f, int m){
int rc;
do{ rc = osOpen(z,f,m); }while( rc<0 && errno==EINTR );
return rc;
}
/* /*
** Helper functions to obtain and relinquish the global mutex. The ** Helper functions to obtain and relinquish the global mutex. The
@@ -354,7 +522,7 @@ static int lockTrace(int fd, int op, struct flock *p){
}else if( op==F_SETLK ){ }else if( op==F_SETLK ){
zOpName = "SETLK"; zOpName = "SETLK";
}else{ }else{
s = fcntl(fd, op, p); s = osFcntl(fd, op, p);
sqlite3DebugPrintf("fcntl unknown %d %d %d\n", fd, op, s); sqlite3DebugPrintf("fcntl unknown %d %d %d\n", fd, op, s);
return s; return s;
} }
@@ -368,7 +536,7 @@ static int lockTrace(int fd, int op, struct flock *p){
assert( 0 ); assert( 0 );
} }
assert( p->l_whence==SEEK_SET ); assert( p->l_whence==SEEK_SET );
s = fcntl(fd, op, p); s = osFcntl(fd, op, p);
savedErrno = errno; savedErrno = errno;
sqlite3DebugPrintf("fcntl %d %d %s %s %d %d %d %d\n", sqlite3DebugPrintf("fcntl %d %d %s %s %d %d %d %d\n",
threadid, fd, zOpName, zType, (int)p->l_start, (int)p->l_len, threadid, fd, zOpName, zType, (int)p->l_start, (int)p->l_len,
@@ -376,7 +544,7 @@ static int lockTrace(int fd, int op, struct flock *p){
if( s==(-1) && op==F_SETLK && (p->l_type==F_RDLCK || p->l_type==F_WRLCK) ){ if( s==(-1) && op==F_SETLK && (p->l_type==F_RDLCK || p->l_type==F_WRLCK) ){
struct flock l2; struct flock l2;
l2 = *p; l2 = *p;
fcntl(fd, F_GETLK, &l2); osFcntl(fd, F_GETLK, &l2);
if( l2.l_type==F_RDLCK ){ if( l2.l_type==F_RDLCK ){
zType = "RDLCK"; zType = "RDLCK";
}else if( l2.l_type==F_WRLCK ){ }else if( l2.l_type==F_WRLCK ){
@@ -392,23 +560,18 @@ static int lockTrace(int fd, int op, struct flock *p){
errno = savedErrno; errno = savedErrno;
return s; return s;
} }
#define fcntl lockTrace #undef osFcntl
#define osFcntl lockTrace
#endif /* SQLITE_LOCK_TRACE */ #endif /* SQLITE_LOCK_TRACE */
/* /*
** Retry ftruncate() calls that fail due to EINTR ** Retry ftruncate() calls that fail due to EINTR
*/ */
#ifdef EINTR
static int robust_ftruncate(int h, sqlite3_int64 sz){ static int robust_ftruncate(int h, sqlite3_int64 sz){
int rc; int rc;
do{ rc = ftruncate(h,sz); }while( rc<0 && errno==EINTR ); do{ rc = osFtruncate(h,sz); }while( rc<0 && errno==EINTR );
return rc; return rc;
} }
#else
# define robust_ftruncate(a,b) ftruncate(a,b)
#endif
/* /*
** This routine translates a standard POSIX errno code into something ** This routine translates a standard POSIX errno code into something
@@ -835,7 +998,7 @@ static int unixLogErrorAtLine(
** and move on. ** and move on.
*/ */
static void robust_close(unixFile *pFile, int h, int lineno){ static void robust_close(unixFile *pFile, int h, int lineno){
if( close(h) ){ if( osClose(h) ){
unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close", unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
pFile ? pFile->zPath : 0, lineno); pFile ? pFile->zPath : 0, lineno);
} }
@@ -912,7 +1075,7 @@ static int findInodeInfo(
** create a unique name for the file. ** create a unique name for the file.
*/ */
fd = pFile->h; fd = pFile->h;
rc = fstat(fd, &statbuf); rc = osFstat(fd, &statbuf);
if( rc!=0 ){ if( rc!=0 ){
pFile->lastErrno = errno; pFile->lastErrno = errno;
#ifdef EOVERFLOW #ifdef EOVERFLOW
@@ -933,12 +1096,12 @@ static int findInodeInfo(
** the first page of the database, no damage is done. ** the first page of the database, no damage is done.
*/ */
if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){ if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
do{ rc = write(fd, "S", 1); }while( rc<0 && errno==EINTR ); do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR );
if( rc!=1 ){ if( rc!=1 ){
pFile->lastErrno = errno; pFile->lastErrno = errno;
return SQLITE_IOERR; return SQLITE_IOERR;
} }
rc = fstat(fd, &statbuf); rc = osFstat(fd, &statbuf);
if( rc!=0 ){ if( rc!=0 ){
pFile->lastErrno = errno; pFile->lastErrno = errno;
return SQLITE_IOERR; return SQLITE_IOERR;
@@ -1007,7 +1170,7 @@ static int unixCheckReservedLock(sqlite3_file *id, int *pResOut){
lock.l_start = RESERVED_BYTE; lock.l_start = RESERVED_BYTE;
lock.l_len = 1; lock.l_len = 1;
lock.l_type = F_WRLCK; lock.l_type = F_WRLCK;
if (-1 == fcntl(pFile->h, F_GETLK, &lock)) { if (-1 == osFcntl(pFile->h, F_GETLK, &lock)) {
int tErrno = errno; int tErrno = errno;
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK); rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK);
pFile->lastErrno = tErrno; pFile->lastErrno = tErrno;
@@ -1160,7 +1323,7 @@ static int unixLock(sqlite3_file *id, int eFileLock){
){ ){
lock.l_type = (eFileLock==SHARED_LOCK?F_RDLCK:F_WRLCK); lock.l_type = (eFileLock==SHARED_LOCK?F_RDLCK:F_WRLCK);
lock.l_start = PENDING_BYTE; lock.l_start = PENDING_BYTE;
s = fcntl(pFile->h, F_SETLK, &lock); s = osFcntl(pFile->h, F_SETLK, &lock);
if( s==(-1) ){ if( s==(-1) ){
tErrno = errno; tErrno = errno;
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
@@ -1182,14 +1345,14 @@ static int unixLock(sqlite3_file *id, int eFileLock){
/* Now get the read-lock */ /* Now get the read-lock */
lock.l_start = SHARED_FIRST; lock.l_start = SHARED_FIRST;
lock.l_len = SHARED_SIZE; lock.l_len = SHARED_SIZE;
if( (s = fcntl(pFile->h, F_SETLK, &lock))==(-1) ){ if( (s = osFcntl(pFile->h, F_SETLK, &lock))==(-1) ){
tErrno = errno; tErrno = errno;
} }
/* Drop the temporary PENDING lock */ /* Drop the temporary PENDING lock */
lock.l_start = PENDING_BYTE; lock.l_start = PENDING_BYTE;
lock.l_len = 1L; lock.l_len = 1L;
lock.l_type = F_UNLCK; lock.l_type = F_UNLCK;
if( fcntl(pFile->h, F_SETLK, &lock)!=0 ){ if( osFcntl(pFile->h, F_SETLK, &lock)!=0 ){
if( s != -1 ){ if( s != -1 ){
/* This could happen with a network mount */ /* This could happen with a network mount */
tErrno = errno; tErrno = errno;
@@ -1232,7 +1395,7 @@ static int unixLock(sqlite3_file *id, int eFileLock){
default: default:
assert(0); assert(0);
} }
s = fcntl(pFile->h, F_SETLK, &lock); s = osFcntl(pFile->h, F_SETLK, &lock);
if( s==(-1) ){ if( s==(-1) ){
tErrno = errno; tErrno = errno;
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
@@ -1368,7 +1531,7 @@ static int _posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
lock.l_whence = SEEK_SET; lock.l_whence = SEEK_SET;
lock.l_start = SHARED_FIRST; lock.l_start = SHARED_FIRST;
lock.l_len = divSize; lock.l_len = divSize;
if( fcntl(h, F_SETLK, &lock)==(-1) ){ if( osFcntl(h, F_SETLK, &lock)==(-1) ){
tErrno = errno; tErrno = errno;
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
if( IS_LOCK_ERROR(rc) ){ if( IS_LOCK_ERROR(rc) ){
@@ -1380,7 +1543,7 @@ static int _posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
lock.l_whence = SEEK_SET; lock.l_whence = SEEK_SET;
lock.l_start = SHARED_FIRST; lock.l_start = SHARED_FIRST;
lock.l_len = divSize; lock.l_len = divSize;
if( fcntl(h, F_SETLK, &lock)==(-1) ){ if( osFcntl(h, F_SETLK, &lock)==(-1) ){
tErrno = errno; tErrno = errno;
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK); rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK);
if( IS_LOCK_ERROR(rc) ){ if( IS_LOCK_ERROR(rc) ){
@@ -1392,7 +1555,7 @@ static int _posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
lock.l_whence = SEEK_SET; lock.l_whence = SEEK_SET;
lock.l_start = SHARED_FIRST+divSize; lock.l_start = SHARED_FIRST+divSize;
lock.l_len = SHARED_SIZE-divSize; lock.l_len = SHARED_SIZE-divSize;
if( fcntl(h, F_SETLK, &lock)==(-1) ){ if( osFcntl(h, F_SETLK, &lock)==(-1) ){
tErrno = errno; tErrno = errno;
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
if( IS_LOCK_ERROR(rc) ){ if( IS_LOCK_ERROR(rc) ){
@@ -1407,7 +1570,7 @@ static int _posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
lock.l_whence = SEEK_SET; lock.l_whence = SEEK_SET;
lock.l_start = SHARED_FIRST; lock.l_start = SHARED_FIRST;
lock.l_len = SHARED_SIZE; lock.l_len = SHARED_SIZE;
if( fcntl(h, F_SETLK, &lock)==(-1) ){ if( osFcntl(h, F_SETLK, &lock)==(-1) ){
tErrno = errno; tErrno = errno;
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK); rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK);
if( IS_LOCK_ERROR(rc) ){ if( IS_LOCK_ERROR(rc) ){
@@ -1421,7 +1584,7 @@ static int _posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
lock.l_whence = SEEK_SET; lock.l_whence = SEEK_SET;
lock.l_start = PENDING_BYTE; lock.l_start = PENDING_BYTE;
lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE ); lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE );
if( fcntl(h, F_SETLK, &lock)!=(-1) ){ if( osFcntl(h, F_SETLK, &lock)!=(-1) ){
pInode->eFileLock = SHARED_LOCK; pInode->eFileLock = SHARED_LOCK;
}else{ }else{
tErrno = errno; tErrno = errno;
@@ -1445,7 +1608,7 @@ static int _posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
SimulateIOErrorBenign(1); SimulateIOErrorBenign(1);
SimulateIOError( h=(-1) ) SimulateIOError( h=(-1) )
SimulateIOErrorBenign(0); SimulateIOErrorBenign(0);
if( fcntl(h, F_SETLK, &lock)!=(-1) ){ if( osFcntl(h, F_SETLK, &lock)!=(-1) ){
pInode->eFileLock = NO_LOCK; pInode->eFileLock = NO_LOCK;
}else{ }else{
tErrno = errno; tErrno = errno;
@@ -1647,7 +1810,7 @@ static int dotlockCheckReservedLock(sqlite3_file *id, int *pResOut) {
}else{ }else{
/* The lock is held if and only if the lockfile exists */ /* The lock is held if and only if the lockfile exists */
const char *zLockFile = (const char*)pFile->lockingContext; const char *zLockFile = (const char*)pFile->lockingContext;
reserved = access(zLockFile, 0)==0; reserved = osAccess(zLockFile, 0)==0;
} }
OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved)); OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved));
*pResOut = reserved; *pResOut = reserved;
@@ -1701,7 +1864,7 @@ static int dotlockLock(sqlite3_file *id, int eFileLock) {
} }
/* grab an exclusive lock */ /* grab an exclusive lock */
fd = open(zLockFile,O_RDONLY|O_CREAT|O_EXCL,0600); fd = robust_open(zLockFile,O_RDONLY|O_CREAT|O_EXCL,0600);
if( fd<0 ){ if( fd<0 ){
/* failed to open/create the file, someone else may have stolen the lock */ /* failed to open/create the file, someone else may have stolen the lock */
int tErrno = errno; int tErrno = errno;
@@ -2706,10 +2869,10 @@ static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){
#endif #endif
TIMER_START; TIMER_START;
#if defined(USE_PREAD) #if defined(USE_PREAD)
do{ got = pread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); do{ got = osPread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
SimulateIOError( got = -1 ); SimulateIOError( got = -1 );
#elif defined(USE_PREAD64) #elif defined(USE_PREAD64)
do{ got = pread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); do{ got = osPread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR);
SimulateIOError( got = -1 ); SimulateIOError( got = -1 );
#else #else
newOffset = lseek(id->h, offset, SEEK_SET); newOffset = lseek(id->h, offset, SEEK_SET);
@@ -2722,7 +2885,7 @@ static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){
} }
return -1; return -1;
} }
do{ got = read(id->h, pBuf, cnt); }while( got<0 && errno==EINTR ); do{ got = osRead(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
#endif #endif
TIMER_END; TIMER_END;
if( got<0 ){ if( got<0 ){
@@ -2784,9 +2947,9 @@ static int seekAndWrite(unixFile *id, i64 offset, const void *pBuf, int cnt){
#endif #endif
TIMER_START; TIMER_START;
#if defined(USE_PREAD) #if defined(USE_PREAD)
do{ got = pwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); do{ got = osPwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
#elif defined(USE_PREAD64) #elif defined(USE_PREAD64)
do{ got = pwrite64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); do{ got = osPwrite64(id->h, pBuf, cnt, offset);}while( got<0 && errno==EINTR);
#else #else
newOffset = lseek(id->h, offset, SEEK_SET); newOffset = lseek(id->h, offset, SEEK_SET);
if( newOffset!=offset ){ if( newOffset!=offset ){
@@ -2797,7 +2960,7 @@ static int seekAndWrite(unixFile *id, i64 offset, const void *pBuf, int cnt){
} }
return -1; return -1;
} }
do{ got = write(id->h, pBuf, cnt); }while( got<0 && errno==EINTR ); do{ got = osWrite(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
#endif #endif
TIMER_END; TIMER_END;
if( got<0 ){ if( got<0 ){
@@ -2965,7 +3128,7 @@ static int full_fsync(int fd, int fullSync, int dataOnly){
rc = SQLITE_OK; rc = SQLITE_OK;
#elif HAVE_FULLFSYNC #elif HAVE_FULLFSYNC
if( fullSync ){ if( fullSync ){
rc = fcntl(fd, F_FULLFSYNC, 0); rc = osFcntl(fd, F_FULLFSYNC, 0);
}else{ }else{
rc = 1; rc = 1;
} }
@@ -3112,7 +3275,7 @@ static int unixFileSize(sqlite3_file *id, i64 *pSize){
int rc; int rc;
struct stat buf; struct stat buf;
assert( id ); assert( id );
rc = fstat(((unixFile*)id)->h, &buf); rc = osFstat(((unixFile*)id)->h, &buf);
SimulateIOError( rc=1 ); SimulateIOError( rc=1 );
if( rc!=0 ){ if( rc!=0 ){
((unixFile*)id)->lastErrno = errno; ((unixFile*)id)->lastErrno = errno;
@@ -3153,14 +3316,14 @@ static int fcntlSizeHint(unixFile *pFile, i64 nByte){
i64 nSize; /* Required file size */ i64 nSize; /* Required file size */
struct stat buf; /* Used to hold return values of fstat() */ struct stat buf; /* Used to hold return values of fstat() */
if( fstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT; if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT;
nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk; nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
if( nSize>(i64)buf.st_size ){ if( nSize>(i64)buf.st_size ){
#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
int rc; int rc;
do{ do{
rc = posix_fallocate(pFile-.h, buf.st_size, nSize-buf.st_size; rc = osFallocate(pFile->.h, buf.st_size, nSize-buf.st_size;
}while( rc<0 && errno=EINTR ); }while( rc<0 && errno=EINTR );
if( rc ) return SQLITE_IOERR_WRITE; if( rc ) return SQLITE_IOERR_WRITE;
#else #else
@@ -3368,7 +3531,7 @@ static int unixShmSystemLock(
f.l_start = ofst; f.l_start = ofst;
f.l_len = n; f.l_len = n;
rc = fcntl(pShmNode->h, F_SETLK, &f); rc = osFcntl(pShmNode->h, F_SETLK, &f);
rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY; rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY;
/* Update the global lock state and do debug tracing */ /* Update the global lock state and do debug tracing */
@@ -3493,7 +3656,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
** with the same permissions. The actual permissions the file is created ** with the same permissions. The actual permissions the file is created
** with are subject to the current umask setting. ** with are subject to the current umask setting.
*/ */
if( fstat(pDbFd->h, &sStat) ){ if( osFstat(pDbFd->h, &sStat) ){
rc = SQLITE_IOERR_FSTAT; rc = SQLITE_IOERR_FSTAT;
goto shm_open_err; goto shm_open_err;
} }
@@ -3526,7 +3689,8 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
goto shm_open_err; goto shm_open_err;
} }
pShmNode->h = open(zShmFilename, O_RDWR|O_CREAT, (sStat.st_mode & 0777)); pShmNode->h = robust_open(zShmFilename, O_RDWR|O_CREAT,
(sStat.st_mode & 0777));
if( pShmNode->h<0 ){ if( pShmNode->h<0 ){
rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename); rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
goto shm_open_err; goto shm_open_err;
@@ -3630,7 +3794,7 @@ static int unixShmMap(
** Check to see if it has been allocated (i.e. if the wal-index file is ** Check to see if it has been allocated (i.e. if the wal-index file is
** large enough to contain the requested region). ** large enough to contain the requested region).
*/ */
if( fstat(pShmNode->h, &sStat) ){ if( osFstat(pShmNode->h, &sStat) ){
rc = SQLITE_IOERR_SHMSIZE; rc = SQLITE_IOERR_SHMSIZE;
goto shmpage_out; goto shmpage_out;
} }
@@ -4089,7 +4253,7 @@ static const sqlite3_io_methods *autolockIoFinderImpl(
lockInfo.l_start = 0; lockInfo.l_start = 0;
lockInfo.l_whence = SEEK_SET; lockInfo.l_whence = SEEK_SET;
lockInfo.l_type = F_RDLCK; lockInfo.l_type = F_RDLCK;
if( fcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) { if( osFcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) {
if( strcmp(fsInfo.f_fstypename, "nfs")==0 ){ if( strcmp(fsInfo.f_fstypename, "nfs")==0 ){
return &nfsIoMethods; return &nfsIoMethods;
} else { } else {
@@ -4131,7 +4295,7 @@ static const sqlite3_io_methods *autolockIoFinderImpl(
lockInfo.l_start = 0; lockInfo.l_start = 0;
lockInfo.l_whence = SEEK_SET; lockInfo.l_whence = SEEK_SET;
lockInfo.l_type = F_RDLCK; lockInfo.l_type = F_RDLCK;
if( fcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) { if( osFcntl(pNew->h, F_GETLK, &lockInfo)!=-1 ) {
return &posixIoMethods; return &posixIoMethods;
}else{ }else{
return &semIoMethods; return &semIoMethods;
@@ -4354,10 +4518,10 @@ static int openDirectory(const char *zFilename, int *pFd){
for(ii=(int)strlen(zDirname); ii>1 && zDirname[ii]!='/'; ii--); for(ii=(int)strlen(zDirname); ii>1 && zDirname[ii]!='/'; ii--);
if( ii>0 ){ if( ii>0 ){
zDirname[ii] = '\0'; zDirname[ii] = '\0';
fd = open(zDirname, O_RDONLY|O_BINARY, 0); fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0);
if( fd>=0 ){ if( fd>=0 ){
#ifdef FD_CLOEXEC #ifdef FD_CLOEXEC
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC); osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
#endif #endif
OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname)); OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname));
} }
@@ -4387,9 +4551,9 @@ static const char *unixTempFileDir(void){
if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR"); if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){ for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
if( zDir==0 ) continue; if( zDir==0 ) continue;
if( stat(zDir, &buf) ) continue; if( osStat(zDir, &buf) ) continue;
if( !S_ISDIR(buf.st_mode) ) continue; if( !S_ISDIR(buf.st_mode) ) continue;
if( access(zDir, 07) ) continue; if( osAccess(zDir, 07) ) continue;
break; break;
} }
return zDir; return zDir;
@@ -4432,7 +4596,7 @@ static int unixGetTempname(int nBuf, char *zBuf){
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ]; zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
} }
zBuf[j] = 0; zBuf[j] = 0;
}while( access(zBuf,0)==0 ); }while( osAccess(zBuf,0)==0 );
return SQLITE_OK; return SQLITE_OK;
} }
@@ -4693,7 +4857,7 @@ static int unixOpen(
assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL ); assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL );
return rc; return rc;
} }
fd = open(zName, openFlags, openMode); fd = robust_open(zName, openFlags, openMode);
OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags)); OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
if( fd<0 && errno!=EISDIR && isReadWrite && !isExclusive ){ if( fd<0 && errno!=EISDIR && isReadWrite && !isExclusive ){
/* Failed to open the file for read/write access. Try read-only. */ /* Failed to open the file for read/write access. Try read-only. */
@@ -4701,7 +4865,7 @@ static int unixOpen(
openFlags &= ~(O_RDWR|O_CREAT); openFlags &= ~(O_RDWR|O_CREAT);
flags |= SQLITE_OPEN_READONLY; flags |= SQLITE_OPEN_READONLY;
openFlags |= O_RDONLY; openFlags |= O_RDONLY;
fd = open(zName, openFlags, openMode); fd = robust_open(zName, openFlags, openMode);
} }
if( fd<0 ){ if( fd<0 ){
rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName); rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
@@ -4745,7 +4909,7 @@ static int unixOpen(
} }
#ifdef FD_CLOEXEC #ifdef FD_CLOEXEC
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC); osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
#endif #endif
noLock = eType!=SQLITE_OPEN_MAIN_DB; noLock = eType!=SQLITE_OPEN_MAIN_DB;
@@ -4891,7 +5055,7 @@ static int unixAccess(
default: default:
assert(!"Invalid flags argument"); assert(!"Invalid flags argument");
} }
*pResOut = (access(zPath, amode)==0); *pResOut = (osAccess(zPath, amode)==0);
if( flags==SQLITE_ACCESS_EXISTS && *pResOut ){ if( flags==SQLITE_ACCESS_EXISTS && *pResOut ){
struct stat buf; struct stat buf;
if( 0==stat(zPath, &buf) && buf.st_size==0 ){ if( 0==stat(zPath, &buf) && buf.st_size==0 ){
@@ -4933,7 +5097,7 @@ static int unixFullPathname(
sqlite3_snprintf(nOut, zOut, "%s", zPath); sqlite3_snprintf(nOut, zOut, "%s", zPath);
}else{ }else{
int nCwd; int nCwd;
if( getcwd(zOut, nOut-1)==0 ){ if( osGetcwd(zOut, nOut-1)==0 ){
return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath); return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
} }
nCwd = (int)strlen(zOut); nCwd = (int)strlen(zOut);
@@ -5028,7 +5192,7 @@ static int unixRandomness(sqlite3_vfs *NotUsed, int nBuf, char *zBuf){
#if !defined(SQLITE_TEST) #if !defined(SQLITE_TEST)
{ {
int pid, fd; int pid, fd;
fd = open("/dev/urandom", O_RDONLY); fd = robust_open("/dev/urandom", O_RDONLY, 0);
if( fd<0 ){ if( fd<0 ){
time_t t; time_t t;
time(&t); time(&t);
@@ -5038,7 +5202,7 @@ static int unixRandomness(sqlite3_vfs *NotUsed, int nBuf, char *zBuf){
assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf ); assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
nBuf = sizeof(t) + sizeof(pid); nBuf = sizeof(t) + sizeof(pid);
}else{ }else{
do{ nBuf = read(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR ); do{ nBuf = osRead(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR );
robust_close(0, fd, __LINE__); robust_close(0, fd, __LINE__);
} }
} }
@@ -5437,17 +5601,17 @@ static int proxyCreateUnixFile(
} }
} }
if( fd<0 ){ if( fd<0 ){
fd = open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS); fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
terrno = errno; terrno = errno;
if( fd<0 && errno==ENOENT && islockfile ){ if( fd<0 && errno==ENOENT && islockfile ){
if( proxyCreateLockPath(path) == SQLITE_OK ){ if( proxyCreateLockPath(path) == SQLITE_OK ){
fd = open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS); fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
} }
} }
} }
if( fd<0 ){ if( fd<0 ){
openFlags = O_RDONLY; openFlags = O_RDONLY;
fd = open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS); fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
terrno = errno; terrno = errno;
} }
if( fd<0 ){ if( fd<0 ){
@@ -5561,18 +5725,19 @@ static int proxyBreakConchLock(unixFile *pFile, uuid_t myHostID){
goto end_breaklock; goto end_breaklock;
} }
/* read the conch content */ /* read the conch content */
readLen = pread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0); readLen = osPread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0);
if( readLen<PROXY_PATHINDEX ){ if( readLen<PROXY_PATHINDEX ){
sqlite3_snprintf(sizeof(errmsg),errmsg,"read error (len %d)",(int)readLen); sqlite3_snprintf(sizeof(errmsg),errmsg,"read error (len %d)",(int)readLen);
goto end_breaklock; goto end_breaklock;
} }
/* write it out to the temporary break file */ /* write it out to the temporary break file */
fd = open(tPath, (O_RDWR|O_CREAT|O_EXCL), SQLITE_DEFAULT_FILE_PERMISSIONS); fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL),
SQLITE_DEFAULT_FILE_PERMISSIONS);
if( fd<0 ){ if( fd<0 ){
sqlite3_snprintf(sizeof(errmsg), errmsg, "create failed (%d)", errno); sqlite3_snprintf(sizeof(errmsg), errmsg, "create failed (%d)", errno);
goto end_breaklock; goto end_breaklock;
} }
if( pwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){ if( osPwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){
sqlite3_snprintf(sizeof(errmsg), errmsg, "write failed (%d)", errno); sqlite3_snprintf(sizeof(errmsg), errmsg, "write failed (%d)", errno);
goto end_breaklock; goto end_breaklock;
} }
@@ -5618,7 +5783,7 @@ static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){
* 3rd try: break the lock unless the mod time has changed. * 3rd try: break the lock unless the mod time has changed.
*/ */
struct stat buf; struct stat buf;
if( fstat(conchFile->h, &buf) ){ if( osFstat(conchFile->h, &buf) ){
pFile->lastErrno = errno; pFile->lastErrno = errno;
return SQLITE_IOERR_LOCK; return SQLITE_IOERR_LOCK;
} }
@@ -5637,7 +5802,7 @@ static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){
if( nTries==2 ){ if( nTries==2 ){
char tBuf[PROXY_MAXCONCHLEN]; char tBuf[PROXY_MAXCONCHLEN];
int len = pread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0); int len = osPread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0);
if( len<0 ){ if( len<0 ){
pFile->lastErrno = errno; pFile->lastErrno = errno;
return SQLITE_IOERR_LOCK; return SQLITE_IOERR_LOCK;
@@ -5807,16 +5972,16 @@ static int proxyTakeConch(unixFile *pFile){
*/ */
if( rc==SQLITE_OK && createConch ){ if( rc==SQLITE_OK && createConch ){
struct stat buf; struct stat buf;
int err = fstat(pFile->h, &buf); int err = osFstat(pFile->h, &buf);
if( err==0 ){ if( err==0 ){
mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP | mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP |
S_IROTH|S_IWOTH); S_IROTH|S_IWOTH);
/* try to match the database file R/W permissions, ignore failure */ /* try to match the database file R/W permissions, ignore failure */
#ifndef SQLITE_PROXY_DEBUG #ifndef SQLITE_PROXY_DEBUG
fchmod(conchFile->h, cmode); osFchmod(conchFile->h, cmode);
#else #else
do{ do{
rc = fchmod(conchFile->h, cmode); rc = osFchmod(conchFile->h, cmode);
}while( rc==(-1) && errno==EINTR ); }while( rc==(-1) && errno==EINTR );
if( rc!=0 ){ if( rc!=0 ){
int code = errno; int code = errno;
@@ -5842,7 +6007,7 @@ static int proxyTakeConch(unixFile *pFile){
robust_close(pFile, pFile->h, __LINE__); robust_close(pFile, pFile->h, __LINE__);
} }
pFile->h = -1; pFile->h = -1;
int fd = open(pCtx->dbPath, pFile->openFlags, int fd = robust_open(pCtx->dbPath, pFile->openFlags,
SQLITE_DEFAULT_FILE_PERMISSIONS); SQLITE_DEFAULT_FILE_PERMISSIONS);
OSTRACE(("TRANSPROXY: OPEN %d\n", fd)); OSTRACE(("TRANSPROXY: OPEN %d\n", fd));
if( fd>=0 ){ if( fd>=0 ){
@@ -6068,7 +6233,7 @@ static int proxyTransformUnixFile(unixFile *pFile, const char *path) {
struct stat conchInfo; struct stat conchInfo;
int goLockless = 0; int goLockless = 0;
if( stat(pCtx->conchFilePath, &conchInfo) == -1 ) { if( osStat(pCtx->conchFilePath, &conchInfo) == -1 ) {
int err = errno; int err = errno;
if( (err==ENOENT) && (statfs(dbPath, &fsInfo) != -1) ){ if( (err==ENOENT) && (statfs(dbPath, &fsInfo) != -1) ){
goLockless = (fsInfo.f_flags&MNT_RDONLY) == MNT_RDONLY; goLockless = (fsInfo.f_flags&MNT_RDONLY) == MNT_RDONLY;
@@ -6353,7 +6518,7 @@ int sqlite3_os_init(void){
** that filesystem time. ** that filesystem time.
*/ */
#define UNIXVFS(VFSNAME, FINDER) { \ #define UNIXVFS(VFSNAME, FINDER) { \
2, /* iVersion */ \ 3, /* iVersion */ \
sizeof(unixFile), /* szOsFile */ \ sizeof(unixFile), /* szOsFile */ \
MAX_PATHNAME, /* mxPathname */ \ MAX_PATHNAME, /* mxPathname */ \
0, /* pNext */ \ 0, /* pNext */ \
@@ -6372,6 +6537,9 @@ int sqlite3_os_init(void){
unixCurrentTime, /* xCurrentTime */ \ unixCurrentTime, /* xCurrentTime */ \
unixGetLastError, /* xGetLastError */ \ unixGetLastError, /* xGetLastError */ \
unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \ unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
unixSetSystemCall, /* xSetSystemCall */ \
unixGetSystemCall, /* xGetSystemCall */ \
unixNextSystemCall, /* xNextSystemCall */ \
} }
/* /*

View File

@@ -2746,7 +2746,7 @@ static int winGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
*/ */
int sqlite3_os_init(void){ int sqlite3_os_init(void){
static sqlite3_vfs winVfs = { static sqlite3_vfs winVfs = {
2, /* iVersion */ 3, /* iVersion */
sizeof(winFile), /* szOsFile */ sizeof(winFile), /* szOsFile */
MAX_PATH, /* mxPathname */ MAX_PATH, /* mxPathname */
0, /* pNext */ 0, /* pNext */
@@ -2765,6 +2765,9 @@ int sqlite3_os_init(void){
winCurrentTime, /* xCurrentTime */ winCurrentTime, /* xCurrentTime */
winGetLastError, /* xGetLastError */ winGetLastError, /* xGetLastError */
winCurrentTimeInt64, /* xCurrentTimeInt64 */ winCurrentTimeInt64, /* xCurrentTimeInt64 */
0, /* xSetSystemCall */
0, /* xGetSystemCall */
0, /* xNextSystemCall */
}; };
#ifndef SQLITE_OMIT_WAL #ifndef SQLITE_OMIT_WAL

View File

@@ -893,10 +893,22 @@ typedef struct sqlite3_mutex sqlite3_mutex;
** date and time if that method is available (if iVersion is 2 or ** date and time if that method is available (if iVersion is 2 or
** greater and the function pointer is not NULL) and will fall back ** greater and the function pointer is not NULL) and will fall back
** to xCurrentTime() if xCurrentTimeInt64() is unavailable. ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
**
** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
** are not used by the SQLite core. These optional interfaces are provided
** by some VFSes to facilitate testing of the VFS code. By overriding
** system calls with functions under its control, a test program can
** simulate faults and error conditions that would otherwise be difficult
** or impossible to induce. The set of system calls that can be overridden
** varies from one VFS to another, and from one version of the same VFS to the
** next. Applications that use these interfaces must be prepared for any
** or all of these interfaces to be NULL or for their behavior to change
** from one release to the next. Applications must not attempt to access
** any of these methods if the iVersion of the VFS is less than 3.
*/ */
typedef struct sqlite3_vfs sqlite3_vfs; typedef struct sqlite3_vfs sqlite3_vfs;
struct sqlite3_vfs { struct sqlite3_vfs {
int iVersion; /* Structure version number (currently 2) */ int iVersion; /* Structure version number (currently 3) */
int szOsFile; /* Size of subclassed sqlite3_file */ int szOsFile; /* Size of subclassed sqlite3_file */
int mxPathname; /* Maximum file pathname length */ int mxPathname; /* Maximum file pathname length */
sqlite3_vfs *pNext; /* Next registered VFS */ sqlite3_vfs *pNext; /* Next registered VFS */
@@ -922,6 +934,13 @@ struct sqlite3_vfs {
int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*); int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
/* /*
** The methods above are in versions 1 and 2 of the sqlite_vfs object. ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
** Those below are for version 3 and greater.
*/
int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, void *pFunc);
void *(*xGetSystemCall)(sqlite3_vfs*, const char *zName);
const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
/*
** The methods above are in versions 1 through 3 of the sqlite_vfs object.
** New fields may be appended in figure versions. The iVersion ** New fields may be appended in figure versions. The iVersion
** value will increment whenever this happens. ** value will increment whenever this happens.
*/ */