Browse Source

avoid using rand() without seed. use getpid

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1154 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.0
Xuefer 9 years ago
parent
commit
5dea18cc4c
  1. 4
      xcache/xc_lock.c
  2. 9
      xcache/xc_shm_mmap.c

4
xcache/xc_lock.c

@ -87,7 +87,7 @@ xc_lock_t *xc_fcntl_init(const char *pathname) /* {{{ */
char *myname;
if (pathname == NULL) {
static int i = 0;
static int instanceId = 0;
const char default_tmpdir[] = { DEFAULT_SLASH, 't', 'm', 'p', '\0' };
const char *tmpdir;
@ -100,7 +100,7 @@ xc_lock_t *xc_fcntl_init(const char *pathname) /* {{{ */
}
size = strlen(tmpdir) + sizeof("/.xcache.lock") - 1 + 3 * 10 + 100;
myname = malloc(size);
snprintf(myname, size - 1, "%s%c.xcache.%d.%d.%d.lock", tmpdir, DEFAULT_SLASH, (int) getuid(), i ++, rand());
snprintf(myname, size - 1, "%s%c.xcache.%d.%d.%d.lock", tmpdir, DEFAULT_SLASH, (int) getuid(), (int) getpid(), ++instanceId);
pathname = myname;
}
else {

9
xcache/xc_shm_mmap.c

@ -150,22 +150,21 @@ static XC_SHM_INIT(xc_mmap_init) /* {{{ */
xc_shm_t *shm = NULL;
int ro_ok;
volatile void *romem;
char tmpname[sizeof(TMP_PATH) - 1 + 100];
char tmpname[sizeof(TMP_PATH) - 1 + 4 * 10 + 100] = { 0 };
const char *errstr = NULL;
const char *path = (const char *) arg1;
static int instanceId = 0;
CHECK(shm = calloc(1, sizeof(xc_shm_t)), "shm OOM");
shm->size = size;
if (path == NULL || !path[0]) {
static int inc = 0;
snprintf(tmpname, sizeof(tmpname) - 1, "%s.%d.%d.%d.%d", TMP_PATH, (int) getuid(), (int) getpid(), inc ++, rand());
snprintf(tmpname, sizeof(tmpname) - 1, "%s.%d.%d.%d", TMP_PATH, (int) getuid(), (int) getpid(), ++instanceId);
path = tmpname;
}
#ifdef ZEND_WIN32
else {
static int inc2 = 0;
snprintf(tmpname, sizeof(tmpname) - 1, "%s.%d.%d.%d.%d", path, (int) getuid(), (int) getpid(), inc2 ++, rand());
snprintf(tmpname, sizeof(tmpname) - 1, "%s.%d.%d.%d", path, (int) getuid(), (int) getpid(), ++instanceId);
path = tmpname;
}
#endif

Loading…
Cancel
Save