Jeff Dike
9a6f70bbed
random: add async notification support to /dev/random
...
Add async notification support to /dev/random.
A little test case is below. Without this patch, you get:
$ ./async-random
Drained the pool
Found more randomness
With it, you get:
$ ./async-random
Drained the pool
SIGIO
Found more randomness
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include <fcntl.h>
static void handler(int sig)
{
printf("SIGIO\n");
}
int main(int argc, char **argv)
{
int fd, n, err, flags;
if(signal(SIGIO, handler) < 0){
perror("setting SIGIO handler");
exit(1);
}
fd = open("/dev/random", O_RDONLY);
if(fd < 0){
perror("open");
exit(1);
}
flags = fcntl(fd, F_GETFL);
if (flags < 0){
perror("getting flags");
exit(1);
}
flags |= O_NONBLOCK;
if (fcntl(fd, F_SETFL, flags) < 0){
perror("setting flags");
exit(1);
}
while((err = read(fd, &n, sizeof(n))) > 0) ;
if(err == 0){
printf("random returned 0\n");
exit(1);
}
else if(errno != EAGAIN){
perror("read");
exit(1);
}
flags |= O_ASYNC;
if (fcntl(fd, F_SETFL, flags) < 0){
perror("setting flags");
exit(1);
}
if (fcntl(fd, F_SETOWN, getpid()) < 0) {
perror("Setting SIGIO");
exit(1);
}
printf("Drained the pool\n");
read(fd, &n, sizeof(n));
printf("Found more randomness\n");
return(0);
}
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Matt Mackall <mpm@selenic.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-04-29 08:06:25 -07:00
..
2008-04-29 08:06:22 -07:00
2008-04-28 10:03:31 -07:00
2008-04-28 17:29:18 -07:00
2008-04-29 08:06:05 -07:00
2008-04-29 08:06:24 -07:00
2008-04-19 18:17:26 -07:00
2008-04-29 08:06:22 -07:00
2008-04-29 08:06:25 -07:00
2008-04-28 15:05:44 -04:00
2008-03-26 00:58:19 -04:00
2008-04-21 10:19:34 +08:00
2008-04-21 22:38:45 +00:00
2008-04-18 22:22:54 -04:00
2008-04-29 08:06:23 -07:00
2008-04-28 08:58:34 -07:00
2008-04-28 10:03:31 -07:00
2008-03-27 08:40:41 -04:00
2008-04-22 22:16:49 +02:00
2008-04-29 08:06:22 -07:00
2008-04-25 12:24:06 -07:00
2008-04-29 08:06:12 -07:00
2008-04-29 08:06:22 -07:00
2008-04-29 08:06:22 -07:00
2008-04-25 00:06:52 +01:00
2008-04-18 22:16:32 -04:00
2008-04-25 18:57:09 -07:00
2008-04-29 08:06:18 -07:00
2008-04-29 08:06:22 -07:00
2008-04-29 08:06:22 -07:00
2008-04-19 19:10:29 -07:00
2008-04-29 08:06:22 -07:00
2008-04-28 08:58:32 -07:00
2008-04-29 08:06:22 -07:00
2008-04-18 20:05:33 +02:00
2008-04-28 17:31:13 -07:00
2008-04-29 08:06:22 -07:00
2008-04-29 08:06:19 -07:00
2008-04-24 20:58:01 +10:00
2008-04-28 08:58:31 -07:00
2008-04-29 08:06:22 -07:00
2008-04-19 20:40:10 -04:00
2008-04-29 08:06:22 -07:00
2008-04-28 23:44:43 +02:00
2008-04-29 08:06:22 -07:00
2008-04-29 08:06:07 -07:00
2008-04-01 20:43:08 +11:00
2008-04-29 08:06:22 -07:00
2008-04-29 08:06:21 -07:00
2008-04-29 08:06:21 -07:00
2008-04-28 10:51:43 -07:00
2008-04-28 08:58:31 -07:00
2008-04-23 21:25:35 -04:00
2008-04-15 19:35:41 -07:00
2008-04-19 19:10:18 -07:00
2008-04-29 08:06:21 -07:00
2008-04-29 08:06:18 -07:00
2008-04-07 13:14:22 -07:00
2008-04-18 22:22:54 -04:00
2008-04-24 23:57:33 +02:00
2008-04-29 08:06:21 -07:00
2008-04-24 23:57:33 +02:00