Ignore:
Timestamp:
2012-10-18T09:49:35+02:00 (22 months ago)
Author:
moo
Message:

avoid using rand() without seed. use getpid

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xcache/xc_shm_mmap.c

    r1135 r1154  
    151151    int ro_ok; 
    152152    volatile void *romem; 
    153     char tmpname[sizeof(TMP_PATH) - 1 + 100]; 
     153    char tmpname[sizeof(TMP_PATH) - 1 + 4 * 10 + 100] = { 0 }; 
    154154    const char *errstr = NULL; 
    155155    const char *path = (const char *) arg1; 
     156    static int instanceId = 0; 
    156157 
    157158    CHECK(shm = calloc(1, sizeof(xc_shm_t)), "shm OOM"); 
     
    159160 
    160161    if (path == NULL || !path[0]) { 
    161         static int inc = 0; 
    162         snprintf(tmpname, sizeof(tmpname) - 1, "%s.%d.%d.%d.%d", TMP_PATH, (int) getuid(), (int) getpid(), inc ++, rand()); 
     162        snprintf(tmpname, sizeof(tmpname) - 1, "%s.%d.%d.%d", TMP_PATH, (int) getuid(), (int) getpid(), ++instanceId); 
    163163        path = tmpname; 
    164164    } 
    165165#ifdef ZEND_WIN32 
    166166    else { 
    167         static int inc2 = 0; 
    168         snprintf(tmpname, sizeof(tmpname) - 1, "%s.%d.%d.%d.%d", path, (int) getuid(), (int) getpid(), inc2 ++, rand()); 
     167        snprintf(tmpname, sizeof(tmpname) - 1, "%s.%d.%d.%d", path, (int) getuid(), (int) getpid(), ++instanceId); 
    169168        path = tmpname; 
    170169    } 
Note: See TracChangeset for help on using the changeset viewer.