Hi there, This was brought to my attention by a co-worker, and is a legitimate complaint about our device handling for {/dev/null, /dev/random, /dev/urandom, /dev/zero, ...}. Apparently it is not possible to set the device to support non-blocking file I/O, which seems silly as the semantics of the device should permit it. In order for these devices to be used properly from threaded programs based on a select() loop, non-blocking mode is required. Unfortunately, we didn't give the best answer to the initial bug report: Synopsis: Non-blocking IO not supported on /dev/random Responsible-Changed-From-To: freebsd-bugs->markm Responsible-Changed-By: sheldonh Responsible-Changed-When: Wed Jul 12 01:33:02 PDT 2000 Responsible-Changed-Why: Mark Murray has recently re-implemented the random device in the development branch of FreeBSD. This makes him the closest thing we have to a maintainer, although that may just mean you'll have to wait for the new devices to be merged back onto the stable branch. By the way, are you sure /dev/urandom doesn't do what you want? http://www.freebsd.org/cgi/query-pr.cgi?pr=19863 /dev/urandom also does not allow the setting of non-blocking mode. This is probably something that needs to be fixed; it's a pity we didn't catch this before 4.1-RELEASE. I looked through the code some, and noted that /dev/{useful_virtual_stuff} don't implement ioctl(), specifically, support for async I/O, which apparently is required to enable non-blocking I/O (fo_ioctl()). Note that I believe it is insufficient for us to simply provide non-blocking semantics for the device, we actually have to support the flag also for application compatibility. Apparently /dev/random *does* behave correctly on other platforms (Linux, NetBSD, ...) Given that /dev/random is frequently used by security programs, providing correct and consistent semantics is important. This has been demonstrated both in the old /dev/random in 4.x, as well as the revised 5.x devices. Robert N M Watson [EMAIL PROTECTED] http://www.watson.org/~robert/ PGP key fingerprint: AF B5 5F FF A6 4A 79 37 ED 5F 55 E9 58 04 6A B1 TIS Labs at Network Associates, Safeport Network Services ---------- Forwarded message ---------- Date: Tue, 11 Jul 2000 23:41:08 -0700 (PDT) From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: kern/19863: Non-blocking IO not supported on /dev/random >Number: 19863 >Category: kern >Synopsis: Non-blocking IO not supported on /dev/random >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Jul 11 23:50:03 PDT 2000 >Closed-Date: >Last-Modified: >Originator: Mark Andrews >Release: 4.0-stable >Organization: Nominum >Environment: FreeBSD drugs.dv.isc.org 4.0-STABLE FreeBSD 4.0-STABLE #1: Sat Jul 1 00:10:47 EST 2000 [EMAIL PROTECTED]:/usr/src/sys/compile/DRUGS i386 >Description: It is not possible to set /dev/random into non-blocking mode using fcntl. This make it impossible to use /dev/random in a application that requires IO not to block. >How-To-Repeat: #include <fcntl.h> #include <stdio.h> int main(int argc, char **argv) { int fd; int flags; if ((fd = open("/dev/random", O_RDONLY, 0)) == -1) { perror("open"); exit(1); } if ((flags = fcntl(fd, F_GETFL, 0)) == -1) { perror("fcntl: F_GETFL"); exit(1); } flags |= O_NONBLOCK; if (fcntl(fd, F_SETFL, flags) == -1) { perror("fcntl: F_SETFL"); exit(1); } close(fd); exit(0); } >Fix: >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-bugs" in the body of the message To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message