Changeset 57 in svn for trunk/mmap.c


Ignore:
Timestamp:
2006-06-02T03:55:05+02:00 (9 years ago)
Author:
Xuefer
Message:

never unlink the file not created by XCache

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mmap.c

    r21 r57  
    1212#   define ftruncate chsize
    1313#   define getuid() 0
    14 #   define XcacheCreateFileMapping(size, perm, name) \
     14#   define XCacheCreateFileMapping(size, perm, name) \
    1515        CreateFileMapping(INVALID_HANDLE_VALUE, NULL, perm, (sizeof(xc_shmsize_t) > 4) ? size >> 32 : 0, size & 0xffffffff, name)
    1616#   define XCACHE_MAP_FAILED NULL
     
    4343    xc_shmsize_t size;
    4444    char *name;
     45    int newfile;
    4546#ifdef ZEND_WIN32
    4647    HANDLE hmap;
     
    123124    if (shm->name) {
    124125#ifdef __CYGWIN__
    125         unlink(shm->name);
     126        if (shm->newfile) {
     127            unlink(shm->name);
     128        }
    126129#endif
    127130        free(shm->name);
     
    165168    if (fd == -1) {
    166169        fd = open(shm->name, O_CREAT | O_RDWR, XCACHE_MMAP_PERMISSION);
     170        shm->newfile = 1;
    167171        if (fd == -1) {
    168172            goto err;
    169173        }
    170174    }
     175    if (strncmp(shm->name, "/tmp", 4) == 0) {
     176        shm->newfile = 0;
     177    }
    171178    ftruncate(fd, size);
    172179#endif
    173180
    174181#ifdef ZEND_WIN32
    175     shm->hmap = XcacheCreateFileMapping(size, PAGE_READWRITE, shm->name);
     182    shm->hmap = XCacheCreateFileMapping(size, PAGE_READWRITE, shm->name);
    176183    shm->ptr = (LPSTR) MapViewOfFile(shm->hmap, FILE_MAP_WRITE, 0, 0, 0);
    177184#else
     
    187194    if (readonly_protection) {
    188195#ifdef ZEND_WIN32
    189         shm->hmap_ro = XcacheCreateFileMapping(size, PAGE_READONLY, shm->name);
     196        shm->hmap_ro = XCacheCreateFileMapping(size, PAGE_READONLY, shm->name);
    190197        shm->ptr_ro = (LPSTR) MapViewOfFile(shm->hmap_ro, FILE_MAP_READ, 0, 0, 0);
    191198#else
     
    226233    close(fd);
    227234#ifndef __CYGWIN__
    228     unlink(shm->name);
     235    if (shm->newfile) {
     236        unlink(shm->name);
     237    }
    229238#endif
    230239
Note: See TracChangeset for help on using the changeset viewer.