From owner-freebsd-hackers Wed Feb 5 18:13:21 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id SAA04986 for hackers-outgoing; Wed, 5 Feb 1997 18:13:21 -0800 (PST) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id SAA04981 for ; Wed, 5 Feb 1997 18:13:14 -0800 (PST) Received: (from bde@localhost) by godzilla.zeta.org.au (8.8.3/8.6.9) id NAA32068; Thu, 6 Feb 1997 13:08:24 +1100 Date: Thu, 6 Feb 1997 13:08:24 +1100 From: Bruce Evans Message-Id: <199702060208.NAA32068@godzilla.zeta.org.au> To: hackers@FreeBSD.org, jb@cimlogic.com.au Subject: Re: fcntl, F_SETFL, O_NONBLOCK & /dev/null Sender: owner-hackers@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk >I can open /dev/null with O_NONBLOCK. If I open /dev/null without >O_NONBLOCK and then try to fcntl F_SETFL to change the file descriptor >to non-blocking, I get ENODEV returned. Can someone tell me why? fcntl(fd, F_SETFL, O_NONBLOCK) is translated to an FIONBIO ioctl, and the device driver for /dev/null doesn't support this ioctl. None of the memory devices support it. Another problem with the translation is that the flag is supposed to be per-file, but if the FIONBIO ioctl actually does anything, then the flag is sort of per device - a per-file flag is kept in all cases, but it may be inconsistent with the device state. One way to fix this is to remove the FIONBIO calls from fcntl(). This isn't quite right, since it should be possible for drivers to reject O_NONBLOCK (or maybe !O_NONBLOCK). However, in practice most drivers are too stupid to check for O_NONBLOCK in their open routine and too stupid to support FIONBIO in their ioctl routine. This results in the stupid behaviour that you observed. Bruce