diff --git a/ChangeLog b/ChangeLog index 8e207e7d53..48c402cec4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Jan 3 14:01:54 2005 Tanaka Akira + + * random.c (random_seed): don't use /dev/urandom if it is not + character device. + Mon Jan 3 11:37:42 2005 Tanaka Akira * random.c (random_seed): use /dev/urandom if available. diff --git a/random.c b/random.c index e8fa78b944..3f34b04158 100644 --- a/random.c +++ b/random.c @@ -175,17 +175,29 @@ random_seed() unsigned long result; int fd; unsigned long buf; + struct stat statbuf; gettimeofday(&tv, 0); result = tv.tv_sec ^ tv.tv_usec ^ getpid() ^ n++; result += (unsigned long)&result; - if ((fd = open("/dev/urandom", O_RDONLY)) >= 0) { - read(fd, &buf, sizeof(buf)); +#ifdef S_ISCHR + if ((fd = open("/dev/urandom", O_RDONLY|O_NONBLOCK +#ifdef O_NOCTTY + |O_NOCTTY +#endif +#ifdef O_NOFOLLOW + |O_NOFOLLOW +#endif + )) >= 0) { + if (fstat(fd, &statbuf) == 0 && S_ISCHR(statbuf.st_mode)) { + read(fd, &buf, sizeof(buf)); + result ^= buf; + } close(fd); - result ^= buf; } +#endif return result; }