diff options
author | drh <drh@noemail.net> | 2012-04-14 13:25:11 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2012-04-14 13:25:11 +0000 |
commit | 5adc60bab065f318044ada7d4249f25a53e9cb9e (patch) | |
tree | f38ca24102c4ec192f4bc4084095a58cb39b2262 /src/os_unix.c | |
parent | 2b32b9941da808792652ed8e52657e561d5caca5 (diff) | |
download | sqlite-5adc60bab065f318044ada7d4249f25a53e9cb9e.tar.gz sqlite-5adc60bab065f318044ada7d4249f25a53e9cb9e.zip |
In the unix VFS, always set every open file to close-on-exec using either
O_CLOEXEC at open (preferred) or FD_CLOEXEC in an ioctl after opening. Before
this changes, many files were done this way, but not all.
FossilOrigin-Name: 9efbeb11ae0d480a13ff1353820c12f3a8bff452
Diffstat (limited to 'src/os_unix.c')
-rw-r--r-- | src/os_unix.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/os_unix.c b/src/os_unix.c index 559d15649..c85e9b53a 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -165,8 +165,8 @@ #endif /* - ** Default permissions when creating auto proxy dir - */ +** Default permissions when creating auto proxy dir +*/ #ifndef SQLITE_DEFAULT_PROXYDIR_PERMISSIONS # define SQLITE_DEFAULT_PROXYDIR_PERMISSIONS 0755 #endif @@ -512,7 +512,7 @@ static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){ /* ** Invoke open(). Do so multiple times, until it either succeeds or -** files for some reason other than EINTR. +** fails for some reason other than EINTR. ** ** If the file creation mode "m" is 0 then set it to the default for ** SQLite. The default is SQLITE_DEFAULT_FILE_PERMISSIONS (normally @@ -528,7 +528,7 @@ static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){ ** recover the hot journals. */ static int robust_open(const char *z, int f, mode_t m){ - int rc; + int fd; mode_t m2; mode_t origM = 0; if( m==0 ){ @@ -537,11 +537,20 @@ static int robust_open(const char *z, int f, mode_t m){ m2 = m; origM = osUmask(0); } - do{ rc = osOpen(z,f,m2); }while( rc<0 && errno==EINTR ); + do{ +#if defined(O_CLOEXEC) + fd = osOpen(z,f|O_CLOEXEC,m2); +#else + fd = osOpen(z,f,m2); +#endif + }while( fd<0 && errno==EINTR ); if( m ){ osUmask(origM); } - return rc; +#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0) + if( fd>=0 ) osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); +#endif + return fd; } /* @@ -3336,9 +3345,6 @@ static int openDirectory(const char *zFilename, int *pFd){ zDirname[ii] = '\0'; fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0); if( fd>=0 ){ -#ifdef FD_CLOEXEC - osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); -#endif OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname)); } } @@ -5183,10 +5189,6 @@ static int unixOpen( } #endif -#ifdef FD_CLOEXEC - osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); -#endif - noLock = eType!=SQLITE_OPEN_MAIN_DB; |