From e6ed2cfb6c20d5b51bbc6ab288d8ba920dc1c1ac Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 18 Oct 2000 10:39:18 +0000 Subject: 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(-) (limited to 'sys/dev/random') diff --git a/sys/dev/random/randomdev.c b/sys/dev/random/randomdev.c index eaa47b9..c8d2eba 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; } -- cgit v1.1