/ Check-in [149d2ae4]
Login

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

Overview
Comment:Change the xShmSize() implementation in os_unix.c so that it will only increase and never decrease the size of a shared-memory segment.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wal-refactor
Files: files | file ages | folders
SHA1: 149d2ae4a6fe2f86822f286d2a7092c51bec7ebb
User & Date: drh 2010-05-13 08:33:36
Original Comment: Change the xShmSize() implementation in os_unix.c so that it will only increase and never decrease the size of a shared-memory segment.
Context
2010-05-13
08:53
The refactored of VFS SHM primitives are now working so merge the wal-refactor branch back into the trunk. check-in: bce21c18 user: drh tags: trunk
08:33
Change the xShmSize() implementation in os_unix.c so that it will only increase and never decrease the size of a shared-memory segment. Closed-Leaf check-in: 149d2ae4 user: drh tags: wal-refactor
07:08
Fix for a segfault that can follow a malloc failure. check-in: 3cab9022 user: dan tags: wal-refactor
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

  3953   3953   ){
  3954   3954     unixFile *pDbFd = (unixFile*)fd;
  3955   3955     unixShm *p = pDbFd->pShm;
  3956   3956     unixShmFile *pFile = p->pFile;
  3957   3957     int rc = SQLITE_OK;
  3958   3958     struct stat sStat;
  3959   3959   
  3960         -  if( reqSize>=0 ){
         3960  +  /* On a query, this loop runs once.  When reqSize>=0, the loop potentially
         3961  +  ** runs twice, except if the actual size is already greater than or equal
         3962  +  ** to the requested size, reqSize is set to -1 on the first iteration and
         3963  +  ** the loop only runs once.
         3964  +  */
         3965  +  while( 1 ){
         3966  +    if( fstat(pFile->h, &sStat)==0 ){
         3967  +      *pNewSize = (int)sStat.st_size;
         3968  +      if( reqSize>=0 && reqSize<=(int)sStat.st_size ) break;
         3969  +    }else{
         3970  +      *pNewSize = 0;
         3971  +      rc = SQLITE_IOERR;
         3972  +      break;
         3973  +    }
         3974  +    if( reqSize<0 ) break;
  3961   3975       reqSize = (reqSize + SQLITE_UNIX_SHM_INCR - 1)/SQLITE_UNIX_SHM_INCR;
  3962   3976       reqSize *= SQLITE_UNIX_SHM_INCR;
  3963   3977       rc = ftruncate(pFile->h, reqSize);
  3964         -  }
  3965         -  if( fstat(pFile->h, &sStat)==0 ){
  3966         -    *pNewSize = (int)sStat.st_size;
  3967         -  }else{
  3968         -    *pNewSize = 0;
  3969         -    rc = SQLITE_IOERR;
         3978  +    reqSize = -1;
  3970   3979     }
  3971   3980     return rc;
  3972   3981   }
  3973   3982   
  3974   3983   
  3975   3984   /*
  3976   3985   ** Map the shared storage into memory.  The minimum size of the