Unified · Split
| @@ -162,37 +162,25 @@ procwakeup(Proc *p) · 161 unmodified lines | |||
| 162 | pthread_mutex_unlock(&op->mutex); | 162 | pthread_mutex_unlock(&op->mutex); |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | int randfd; | 165 | static int randfd; |
| 166 | #undef open | 166 | #undef open |
| 167 | void | 167 | void |
| 168 | randominit(void) | 168 | randominit(void) |
| 169 | { | 169 | { |
| 170 | #ifdef USE_RANDOM | ||
| 171 | srandom(getpid()+fastticks(nil)+ticks()); | ||
| 172 | #else | ||
| 173 | if((randfd = open("/dev/urandom", OREAD)) < 0) | 170 | if((randfd = open("/dev/urandom", OREAD)) < 0) |
| 174 | if((randfd = open("/dev/random", OREAD)) < 0) | 171 | if((randfd = open("/dev/random", OREAD)) < 0) |
| 175 | panic("open /dev/random: %r"); | 172 | panic("open /dev/random: %r"); |
| 176 | #endif | ||
| 177 | } | 173 | } |
| 178 | 174 | ||
| 179 | #undef read | 175 | #undef read |
| 180 | ulong | 176 | ulong |
| 181 | randomread(void *v, ulong n) | 177 | randomread(void *v, ulong n) |
| 182 | { | 178 | { |
| 183 | #ifdef USE_RANDOM | ||
| 184 | int i; | ||
| 185 | |||
| 186 | for(i=0; i<n; i++) | ||
| 187 | ((uchar*)v)[i] = random(); | ||
| 188 | return n; | ||
| 189 | #else | ||
| 190 | int m; | 179 | int m; |
| 191 | 180 | ||
| 192 | if((m = read(randfd, v, n)) != n) | 181 | if((m = read(randfd, v, n)) != n) |
| 193 | panic("short read from /dev/random: %d but %d", n, m); | 182 | panic("short read from /dev/random: %d but %d", n, m); |
| 194 | return m; | 183 | return m; |
| 195 | #endif | ||
| 196 | } | 184 | } |
| 197 | 185 | ||
| 198 | #undef time | 186 | #undef time |