if /dev/urandom is not available use rand() to get a random node name

This commit is contained in:
antirez
2011-05-04 10:30:22 +02:00
parent 35845afba0
commit a5dce40726
2 changed files with 4 additions and 6 deletions

View File

@ -24,12 +24,10 @@ void clusterGetRandomName(char *p) {
char *charset = "0123456789abcdef";
int j;
if (!fp) {
redisLog(REDIS_WARNING,
"Unrecovarable error: can't open /dev/urandom:%s" ,strerror(errno));
exit(1);
if (fp == NULL || fread(p,REDIS_CLUSTER_NAMELEN,1,fp) == 0) {
for (j = 0; j < REDIS_CLUSTER_NAMELEN; j++)
p[j] = rand();
}
fread(p,REDIS_CLUSTER_NAMELEN,1,fp);
for (j = 0; j < REDIS_CLUSTER_NAMELEN; j++)
p[j] = charset[p[j] & 0x0F];
fclose(fp);