diff options
author | drh <drh@noemail.net> | 2011-06-20 10:44:10 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2011-06-20 10:44:10 +0000 |
commit | 8863f35f5ca84317c5eb43ff2c40906b2bb6dc54 (patch) | |
tree | 6ac30e1228b07e16cbde3d74c9ca39c2839b68d2 /src/os_unix.c | |
parent | bf0ed47d82328aa2517e99d60b56b4c95cad17cd (diff) | |
parent | d80138af2c42ea2f1cd9627823281f6b1e20525e (diff) | |
download | sqlite-8863f35f5ca84317c5eb43ff2c40906b2bb6dc54.tar.gz sqlite-8863f35f5ca84317c5eb43ff2c40906b2bb6dc54.zip |
Merge the latest trunk changes into the sessions branch.
FossilOrigin-Name: 4c5e276c902e0b93cfc05bf2e1db966ecdac0ed0
Diffstat (limited to 'src/os_unix.c')
-rw-r--r-- | src/os_unix.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/os_unix.c b/src/os_unix.c index c768dcfa7..5860ae71a 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3537,7 +3537,8 @@ struct unixShmNode { char *zFilename; /* Name of the mmapped file */ int h; /* Open file descriptor */ int szRegion; /* Size of shared-memory regions */ - int nRegion; /* Size of array apRegion */ + u16 nRegion; /* Size of array apRegion */ + u8 isReadonly; /* True if read-only */ char **apRegion; /* Array of mapped shared-memory regions */ int nRef; /* Number of unixShm objects pointing to this */ unixShm *pFirst; /* All unixShm objects pointing to this */ @@ -3784,8 +3785,17 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ pShmNode->h = robust_open(zShmFilename, O_RDWR|O_CREAT, (sStat.st_mode & 0777)); if( pShmNode->h<0 ){ - rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename); - goto shm_open_err; + const char *zRO; + zRO = sqlite3_uri_parameter(pDbFd->zPath, "readonly_shm"); + if( zRO && sqlite3GetBoolean(zRO) ){ + pShmNode->h = robust_open(zShmFilename, O_RDONLY, + (sStat.st_mode & 0777)); + pShmNode->isReadonly = 1; + } + if( pShmNode->h<0 ){ + rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename); + goto shm_open_err; + } } /* Check to see if another process is holding the dead-man switch. @@ -3924,7 +3934,8 @@ static int unixShmMap( while(pShmNode->nRegion<=iRegion){ void *pMem; if( pShmNode->h>=0 ){ - pMem = mmap(0, szRegion, PROT_READ|PROT_WRITE, + pMem = mmap(0, szRegion, + pShmNode->isReadonly ? PROT_READ : PROT_READ|PROT_WRITE, MAP_SHARED, pShmNode->h, pShmNode->nRegion*szRegion ); if( pMem==MAP_FAILED ){ @@ -3950,6 +3961,7 @@ shmpage_out: }else{ *pp = 0; } + if( pShmNode->isReadonly && rc==SQLITE_OK ) rc = SQLITE_READONLY; sqlite3_mutex_leave(pShmNode->mutex); return rc; } |