static void init_random_seed(void)
{
- int fd, ret = -1;
unsigned int seed;
- size_t len = sizeof(unsigned int);
+ int fd, ret = para_open("/dev/urandom", O_RDONLY, 0);
- fd = open("/dev/urandom", O_RDONLY);
- if (fd < 0)
+ if (ret < 0)
+ goto err;
+ fd = ret;
+ ret = read(fd, &seed, sizeof(seed));
+ if (ret < 0) {
+ ret = -ERRNO_TO_PARA_ERROR(errno);
goto out;
- ret = -2;
- if (read(fd, &seed, len) != len)
+ }
+ if (ret != sizeof(seed)) {
+ ret = -ERRNO_TO_PARA_ERROR(EIO);
goto out;
+ }
srandom(seed);
ret = 1;
out:
- if (fd >= 0)
- close(fd);
- if (ret > 0)
+ close(fd);
+ if (ret >= 0)
return;
- PARA_EMERG_LOG("can not seed pseudo random generator (ret = %d)\n",
- ret);
+err:
+ PARA_EMERG_LOG("can not seed pseudo random number generator: %s\n",
+ para_strerror(-ret));
exit(EXIT_FAILURE);
}
(unsigned) afs_socket_cookie);
}
-
static unsigned server_init(int argc, char **argv)
{
/* connector's address information */