From 93d88e0056b793f5526004753b6afef75df4dd3c Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Wed, 18 Oct 2000 10:39:18 +0000 Subject: [PATCH] Attempt to fix the random read blocking. The old code slept at priority "0" and without PCATCH, so it was uninterruptable. And even when it did wake up after entropy arrived, it exited after the wakeup without actually reading the freshly arrived entropy. I sent this to Mark before but it seems he is in transit. Mark: feel free to replace this if it gets in your way. --- sys/dev/random/randomdev.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/sys/dev/random/randomdev.c b/sys/dev/random/randomdev.c index eaa47b9ed5f7..c8d2ebac1ee8 100644 --- a/sys/dev/random/randomdev.c +++ b/sys/dev/random/randomdev.c @@ -109,22 +109,21 @@ random_read(dev_t dev, struct uio *uio, int flag) int error = 0; void *random_buf; - if (flag & IO_NDELAY && !random_state.seeded) { - error = EWOULDBLOCK; - } - else { - if (random_state.seeded) { - c = min(uio->uio_resid, PAGE_SIZE); - random_buf = (void *)malloc(c, M_TEMP, M_WAITOK); - while (uio->uio_resid > 0 && error == 0) { - ret = read_random_real(random_buf, c); - error = uiomove(random_buf, ret, uio); - } - free(random_buf, M_TEMP); - } + while (!random_state.seeded) { + if (flag & IO_NDELAY) + error = EWOULDBLOCK; else - error = tsleep(&random_state, 0, "rndblk", 0); + error = tsleep(&random_state, PUSER|PCATCH, "rndblk", 0); + if (error != 0) + return error; } + c = min(uio->uio_resid, PAGE_SIZE); + random_buf = (void *)malloc(c, M_TEMP, M_WAITOK); + while (uio->uio_resid > 0 && error == 0) { + ret = read_random_real(random_buf, c); + error = uiomove(random_buf, ret, uio); + } + free(random_buf, M_TEMP); return error; }