/ Check-in [9efb74ce]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Simplify the readonly_shm implementation so that it conforms to the implementation on trunk. Update the test cases to agree with the new behavior.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | apple-osx
Files: files | file ages | folders
SHA1: 9efb74cefb2b7444112e16f3da48d5645746fdfa
User & Date: drh 2011-10-11 18:38:13
Context
2011-10-21
17:18
Merge the latest trunk changes into the apple-osx branch. check-in: be62ef05 user: drh tags: apple-osx
2011-10-11
18:38
Simplify the readonly_shm implementation so that it conforms to the implementation on trunk. Update the test cases to agree with the new behavior. check-in: 9efb74ce user: drh tags: apple-osx
15:03
Fix a locking error introduced when porting the new Apple locking code. check-in: cce1f521 user: drh tags: apple-osx
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

  4703   4703       if( pShmNode->mutex==0 ){
  4704   4704         rc = SQLITE_NOMEM;
  4705   4705         goto shm_open_err;
  4706   4706       }
  4707   4707   
  4708   4708       if( pInode->bProcessLock==0 ){
  4709   4709         const char *zRO;
         4710  +      int openFlags = O_RDWR | O_CREAT;
  4710   4711         zRO = sqlite3_uri_parameter(pDbFd->zPath, "readonly_shm");
  4711   4712         if( zRO && sqlite3GetBoolean(zRO) ){
  4712         -        pShmNode->h = robust_open(zShmFilename, O_RDONLY,
  4713         -                                  (sStat.st_mode & 0777));
         4713  +        openFlags = O_RDONLY;
  4714   4714           pShmNode->isReadonly = 1;
  4715         -      }else{
  4716         -        pShmNode->h = robust_open(zShmFilename, O_RDWR|O_CREAT,
  4717         -                               (sStat.st_mode & 0777));
  4718   4715         }
         4716  +      pShmNode->h = robust_open(zShmFilename, openFlags, (sStat.st_mode&0777));
  4719   4717         if( pShmNode->h<0 ){
  4720         -        const char *zRO;
  4721         -        zRO = sqlite3_uri_parameter(pDbFd->zPath, "readonly_shm");
  4722         -        if( zRO && sqlite3GetBoolean(zRO) ){
  4723         -          pShmNode->h = robust_open(zShmFilename, O_RDONLY,
  4724         -                                    (sStat.st_mode & 0777));
  4725         -          pShmNode->isReadonly = 1;
  4726         -        }
  4727         -        if( pShmNode->h<0 ){
  4728         -          rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
  4729         -          goto shm_open_err;
  4730         -        }
         4718  +        rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
         4719  +        goto shm_open_err;
  4731   4720         }
  4732   4721     
  4733   4722         /* Check to see if another process is holding the dead-man switch.
  4734   4723         ** If not, truncate the file to zero length. 
  4735   4724         */
  4736   4725         rc = SQLITE_OK;
  4737   4726         if( unixShmSystemLock(pShmNode, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){

Changes to test/walro.test.

    20     20   # These tests are only going to work on unix.
    21     21   #
    22     22   if {$::tcl_platform(platform) != "unix"} {
    23     23     finish_test
    24     24     return
    25     25   }
    26     26   
    27         -# these tests can't deal with the location of the -shm file under proxy locking
    28         -#
    29         -if {[forced_proxy_locking]} {
    30         -  finish_test
    31         -  return
    32         -}
    33         -
    34     27   # And only if the build is WAL-capable.
    35     28   #
    36     29   ifcapable !wal {
    37     30     finish_test
    38     31     return
    39     32   }
    40     33   
................................................................................
   146    139     do_test 1.3.1 {
   147    140       code1 { db close }
   148    141       code1 { sqlite3 db test.db }
   149    142       csql1 { SELECT * FROM t1 }
   150    143     } {1 {unable to open database file}}
   151    144   
   152    145     # Also test that if the -shm file can be opened for read/write access,
   153         -  # it is, even if readonly_shm=1 is present in the URI.
          146  +  # it is not if readonly_shm=1 is present in the URI.
   154    147     do_test 1.3.2.1 {
   155    148       code1 { db close }
   156    149       code2 { db2 close }
   157    150       file exists test.db-shm
   158    151     } {0}
   159    152     do_test 1.3.2.2 {
   160    153       code1 { sqlite3 db file:test.db?readonly_shm=1 }
   161         -    sql1 { SELECT * FROM t1 }
   162         -  } {a b c d e f g h i j k l}
          154  +    csql1 { SELECT * FROM sqlite_master }
          155  +  } {1 {unable to open database file}}
   163    156     do_test 1.3.2.3 {
   164    157       code1 { db close }
   165    158       close [open test.db-shm w]
   166    159       file attributes test.db-shm -permissions r--r--r--
   167    160       code1 { sqlite3 db file:test.db?readonly_shm=1 }
   168    161       csql1 { SELECT * FROM t1 }
   169    162     } {1 {attempt to write a readonly database}}
   170    163     do_test 1.3.2.4 {
   171    164       code1 { sqlite3_extended_errcode db } 
   172    165     } {SQLITE_READONLY_RECOVERY}
   173    166   }
   174    167   
   175    168   finish_test