Check for signals while reading /dev/urandom. Reading 10MB from

/dev/urandom takes about 38 seconds on a P5/133.  It is useful
to be able to kill such reads almost immediately.  Processes
doing such reads are now scheduled so their denial of service
is no worse than that of processes looping in user mode.
This commit is contained in:
bde 1999-02-02 14:14:05 +00:00
parent e386b727ce
commit 73fc1f731c
2 changed files with 24 additions and 2 deletions

View File

@ -38,7 +38,7 @@
*
* from: Utah $Hdr: mem.c 1.13 89/10/08$
* from: @(#)mem.c 7.2 (Berkeley) 5/9/91
* $Id: mem.c,v 1.52 1998/06/21 11:33:29 bde Exp $
* $Id: mem.c,v 1.53 1998/11/08 12:39:01 dfr Exp $
*/
/*
@ -59,6 +59,7 @@
#include <sys/uio.h>
#include <sys/malloc.h>
#include <sys/proc.h>
#include <sys/signalvar.h>
#include <machine/frame.h>
#include <machine/random.h>
@ -287,6 +288,16 @@ mmrw(dev, uio, flags)
c = iov->iov_len;
break;
}
if (CURSIG(curproc) != 0) {
/*
* Use tsleep() to get the error code right.
* It should return immediately.
*/
error = tsleep(&random_softc[0],
PZERO | PCATCH, "urand", 1);
if (error != 0 && error != EWOULDBLOCK)
continue;
}
if (buf == NULL)
buf = (caddr_t)
malloc(PAGE_SIZE, M_TEMP, M_WAITOK);

View File

@ -38,7 +38,7 @@
*
* from: Utah $Hdr: mem.c 1.13 89/10/08$
* from: @(#)mem.c 7.2 (Berkeley) 5/9/91
* $Id: mem.c,v 1.52 1998/06/21 11:33:29 bde Exp $
* $Id: mem.c,v 1.53 1998/11/08 12:39:01 dfr Exp $
*/
/*
@ -59,6 +59,7 @@
#include <sys/uio.h>
#include <sys/malloc.h>
#include <sys/proc.h>
#include <sys/signalvar.h>
#include <machine/frame.h>
#include <machine/random.h>
@ -287,6 +288,16 @@ mmrw(dev, uio, flags)
c = iov->iov_len;
break;
}
if (CURSIG(curproc) != 0) {
/*
* Use tsleep() to get the error code right.
* It should return immediately.
*/
error = tsleep(&random_softc[0],
PZERO | PCATCH, "urand", 1);
if (error != 0 && error != EWOULDBLOCK)
continue;
}
if (buf == NULL)
buf = (caddr_t)
malloc(PAGE_SIZE, M_TEMP, M_WAITOK);