mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
On unix, ignore the umask when creating journal files. That way, journal files
will have exactly the same permissions as the original database and any process that has permission to write to the database can also recover hot journals. FossilOrigin-Name: 84b324606adc8437338c086404eb157f30f04130
This commit is contained in:
@@ -422,6 +422,9 @@ static struct unix_syscall {
|
||||
{ "fchown", (sqlite3_syscall_ptr)fchown, 0 },
|
||||
#define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)
|
||||
|
||||
{ "umask", (sqlite3_syscall_ptr)umask, 0 },
|
||||
#define osUmask ((mode_t(*)(mode_t))aSyscall[21].pCurrent)
|
||||
|
||||
}; /* End of the overrideable system calls */
|
||||
|
||||
/*
|
||||
@@ -508,11 +511,36 @@ static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){
|
||||
}
|
||||
|
||||
/*
|
||||
** Retry open() calls that fail due to EINTR
|
||||
** Invoke open(). Do so multiple times, until it either succeeds or
|
||||
** files 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
|
||||
** 0644) as modified by the system umask. If m is not 0, then
|
||||
** make the file creation mode be exactly m ignoring the umask.
|
||||
**
|
||||
** The m parameter will be non-zero only when creating -wal, -journal,
|
||||
** and -shm files. We want those files to have *exactly* the same
|
||||
** permissions as their original database, unadulterated by the umask.
|
||||
** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a
|
||||
** transaction crashes and leaves behind hot journals, then any
|
||||
** process that is able to write to the database will also be able to
|
||||
** recover the hot journals.
|
||||
*/
|
||||
static int robust_open(const char *z, int f, int m){
|
||||
static int robust_open(const char *z, int f, mode_t m){
|
||||
int rc;
|
||||
do{ rc = osOpen(z,f,m); }while( rc<0 && errno==EINTR );
|
||||
mode_t m2;
|
||||
mode_t origM;
|
||||
if( m==0 ){
|
||||
m2 = SQLITE_DEFAULT_FILE_PERMISSIONS;
|
||||
}else{
|
||||
m2 = m;
|
||||
origM = osUmask(0);
|
||||
}
|
||||
do{ rc = osOpen(z,f,m2); }while( rc<0 && errno==EINTR );
|
||||
if( m ){
|
||||
osUmask(origM);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3860,8 +3888,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
|
||||
|
||||
/* 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. The actual permissions the file is created
|
||||
** with are subject to the current umask setting.
|
||||
** with the same permissions.
|
||||
*/
|
||||
if( osFstat(pDbFd->h, &sStat) && pInode->bProcessLock==0 ){
|
||||
rc = SQLITE_IOERR_FSTAT;
|
||||
@@ -4892,12 +4919,10 @@ static UnixUnusedFd *findReusableFd(const char *zPath, int flags){
|
||||
** written to *pMode. If an IO error occurs, an SQLite error code is
|
||||
** returned and the value of *pMode is not modified.
|
||||
**
|
||||
** If the file being opened is a temporary file, it is always created with
|
||||
** the octal permissions 0600 (read/writable by owner only). If the file
|
||||
** is a database or master journal file, it is created with the permissions
|
||||
** mask SQLITE_DEFAULT_FILE_PERMISSIONS.
|
||||
**
|
||||
** Finally, if the file being opened is a WAL or regular journal file, then
|
||||
** In most cases cases, this routine sets *pMode to 0, which will become
|
||||
** an indication to robust_open() to create the file using
|
||||
** SQLITE_DEFAULT_FILE_PERMISSIONS adjusted by the umask.
|
||||
** But if the file being opened is a WAL or regular journal file, then
|
||||
** this function queries the file-system for the permissions on the
|
||||
** corresponding database file and sets *pMode to this value. Whenever
|
||||
** possible, WAL and journal files are created using the same permissions
|
||||
@@ -4916,7 +4941,7 @@ static int findCreateFileMode(
|
||||
gid_t *pGid /* OUT: gid to set on the file */
|
||||
){
|
||||
int rc = SQLITE_OK; /* Return Code */
|
||||
*pMode = SQLITE_DEFAULT_FILE_PERMISSIONS;
|
||||
*pMode = 0;
|
||||
*pUid = 0;
|
||||
*pGid = 0;
|
||||
if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
|
||||
@@ -5860,17 +5885,17 @@ static int proxyCreateUnixFile(
|
||||
}
|
||||
}
|
||||
if( fd<0 ){
|
||||
fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
|
||||
fd = robust_open(path, openFlags, 0);
|
||||
terrno = errno;
|
||||
if( fd<0 && errno==ENOENT && islockfile ){
|
||||
if( proxyCreateLockPath(path) == SQLITE_OK ){
|
||||
fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
|
||||
fd = robust_open(path, openFlags, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if( fd<0 ){
|
||||
openFlags = O_RDONLY;
|
||||
fd = robust_open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
|
||||
fd = robust_open(path, openFlags, 0);
|
||||
terrno = errno;
|
||||
}
|
||||
if( fd<0 ){
|
||||
@@ -5994,8 +6019,7 @@ static int proxyBreakConchLock(unixFile *pFile, uuid_t myHostID){
|
||||
goto end_breaklock;
|
||||
}
|
||||
/* write it out to the temporary break file */
|
||||
fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL),
|
||||
SQLITE_DEFAULT_FILE_PERMISSIONS);
|
||||
fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL), 0);
|
||||
if( fd<0 ){
|
||||
sqlite3_snprintf(sizeof(errmsg), errmsg, "create failed (%d)", errno);
|
||||
goto end_breaklock;
|
||||
@@ -6272,8 +6296,7 @@ static int proxyTakeConch(unixFile *pFile){
|
||||
robust_close(pFile, pFile->h, __LINE__);
|
||||
}
|
||||
pFile->h = -1;
|
||||
fd = robust_open(pCtx->dbPath, pFile->openFlags,
|
||||
SQLITE_DEFAULT_FILE_PERMISSIONS);
|
||||
fd = robust_open(pCtx->dbPath, pFile->openFlags, 0);
|
||||
OSTRACE(("TRANSPROXY: OPEN %d\n", fd));
|
||||
if( fd>=0 ){
|
||||
pFile->h = fd;
|
||||
@@ -6842,7 +6865,7 @@ int sqlite3_os_init(void){
|
||||
|
||||
/* Double-check that the aSyscall[] array has been constructed
|
||||
** correctly. See ticket [bb3a86e890c8e96ab] */
|
||||
assert( ArraySize(aSyscall)==21 );
|
||||
assert( ArraySize(aSyscall)==22 );
|
||||
|
||||
/* Register all VFSes defined in the aVfs[] array */
|
||||
for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
|
||||
|
||||
Reference in New Issue
Block a user