- /* For each platform we could do with making a guess at
- * how many FDs we support. With glibc/Linux its possible
- * to use FD_SETSIZE directly, but this may not be very
- * portable. Another options was to use _POSIX_OPEN_MAX
- * but that value is a tad dull on modern hardware. So
- * I ended up trying sizeof(fd_set)*8 which should be
- * closer to the real value.
- * If this causes a problem on your platform because we
- * can not guess correctly then set it to zero.
- */
-# if defined(FD_SETSIZE)
-# define IOWAIT_FD_SETSIZE (FD_SETSIZE)
-# else
- /* fallback method */
-# define IOWAIT_FD_SETSIZE (sizeof(fd_set) * 8)
-# endif
-# define IOWAIT_VARS fd_set fset; struct timeval t
-# define IOWAIT_INIT(f, t) do { \
- FD_ZERO(&fset); \
- if(IOWAIT_FD_SETSIZE > 0 \
- && (f) >= IOWAIT_FD_SETSIZE) \
- { break; } \
- FD_SET((f), &fset); \
- (t)->tv_sec = 0; \
- (t)->tv_usec = 10*1000; \
- /* Spend 10ms on each file. */ \
- } while(0)
-# define IOWAIT_FUNC(f, t) select((f)+1,&fset,NULL,NULL,(t))
-# define IOWAIT_CHECK(f) FD_ISSET((f), &fset)
-#endif
+/* The VOS random() function starts from a static seed so its
+ initial value is predictable. If random() returns the
+ initial value, reseed it with dynamic data. The VOS
+ real-time clock has a granularity of 1 nsec so it should be
+ reasonably difficult to predict its exact value. Do not
+ gratuitously reseed the PRNG because other code in this
+ process or thread may be using it. */
+
+ if (first) {
+ first = 0;
+ rnd = random ();
+ if (rnd == 1804289383) {
+ clock_gettime (CLOCK_REALTIME, &ts);
+ curr_pid = getpid();
+ curr_uid = getuid();
+ seed = ts.tv_sec ^ ts.tv_nsec ^ curr_pid ^ curr_uid;
+ srandom (seed);
+ }
+ }
+
+ for (i = 0; i < sizeof(buf); i++) {
+ if (i % 4 == 0)
+ rnd = random();
+ buf[i] = rnd;
+ rnd >>= 8;
+ }
+ RAND_add(buf, sizeof(buf), ENTROPY_NEEDED);
+ memset(buf, 0, sizeof(buf));