Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Feb 1997 13:08:24 +1100
From:      Bruce Evans <bde@zeta.org.au>
To:        hackers@FreeBSD.org, jb@cimlogic.com.au
Subject:   Re: fcntl, F_SETFL, O_NONBLOCK & /dev/null
Message-ID:  <199702060208.NAA32068@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199702060208.NAA32068>