mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
On unix, if the *-shm file cannot be opened for read/write access, open it
read-only and proceed as if the readonly_shm=1 URI option were specified. FossilOrigin-Name: ba718754fa5ab8596cb84b751051de98afa2706fe6c5df39ad6d925d790719ee
This commit is contained in:
@@ -4369,7 +4369,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
|
||||
struct unixShmNode *pShmNode; /* The underlying mmapped file */
|
||||
int rc = SQLITE_OK; /* Result code */
|
||||
unixInodeInfo *pInode; /* The inode of fd */
|
||||
char *zShmFilename; /* Name of the file used for SHM */
|
||||
char *zShm; /* Name of the file used for SHM */
|
||||
int nShmFilename; /* Size of the SHM filename in bytes */
|
||||
|
||||
/* Allocate space for the new unixShm object. */
|
||||
@@ -4410,14 +4410,14 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
|
||||
goto shm_open_err;
|
||||
}
|
||||
memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
|
||||
zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1];
|
||||
zShm = pShmNode->zFilename = (char*)&pShmNode[1];
|
||||
#ifdef SQLITE_SHM_DIRECTORY
|
||||
sqlite3_snprintf(nShmFilename, zShmFilename,
|
||||
sqlite3_snprintf(nShmFilename, zShm,
|
||||
SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
|
||||
(u32)sStat.st_ino, (u32)sStat.st_dev);
|
||||
#else
|
||||
sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", zBasePath);
|
||||
sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
|
||||
sqlite3_snprintf(nShmFilename, zShm, "%s-shm", zBasePath);
|
||||
sqlite3FileSuffix3(pDbFd->zPath, zShm);
|
||||
#endif
|
||||
pShmNode->h = -1;
|
||||
pDbFd->pInode->pShmNode = pShmNode;
|
||||
@@ -4431,15 +4431,16 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
|
||||
}
|
||||
|
||||
if( pInode->bProcessLock==0 ){
|
||||
int openFlags = O_RDWR | O_CREAT;
|
||||
if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
|
||||
openFlags = O_RDONLY;
|
||||
pShmNode->isReadonly = 1;
|
||||
if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
|
||||
pShmNode->h = robust_open(zShm, O_RDWR|O_CREAT, (sStat.st_mode&0777));
|
||||
}
|
||||
pShmNode->h = robust_open(zShmFilename, openFlags, (sStat.st_mode&0777));
|
||||
if( pShmNode->h<0 ){
|
||||
rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
|
||||
goto shm_open_err;
|
||||
pShmNode->h = robust_open(zShm, O_RDONLY, (sStat.st_mode&0777));
|
||||
if( pShmNode->h<0 ){
|
||||
rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShm);
|
||||
goto shm_open_err;
|
||||
}
|
||||
pShmNode->isReadonly = 1;
|
||||
}
|
||||
|
||||
/* If this process is running as root, make sure that the SHM file
|
||||
|
||||
Reference in New Issue
Block a user