Changeset 1154 in svn


Ignore:
Timestamp:
2012-10-18T09:49:35+02:00 (3 years ago)
Author:
Xuefer
Message:

avoid using rand() without seed. use getpid

Location:
trunk/xcache
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/xcache/xc_lock.c

    r1027 r1154  
    8888
    8989    if (pathname == NULL) {
    90         static int i = 0;
     90        static int instanceId = 0;
    9191        const char default_tmpdir[] = { DEFAULT_SLASH, 't', 'm', 'p', '\0' };
    9292        const char *tmpdir;
     
    101101        size = strlen(tmpdir) + sizeof("/.xcache.lock") - 1 + 3 * 10 + 100;
    102102        myname = malloc(size);
    103         snprintf(myname, size - 1, "%s%c.xcache.%d.%d.%d.lock", tmpdir, DEFAULT_SLASH, (int) getuid(), i ++, rand());
     103        snprintf(myname, size - 1, "%s%c.xcache.%d.%d.%d.lock", tmpdir, DEFAULT_SLASH, (int) getuid(), (int) getpid(), ++instanceId);
    104104        pathname = myname;
    105105    }
  • 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.