Background processes setting O_NONBLOCK on ttys
jilles at stack.nl
Thu Jan 13 03:06:00 PST 2005
On Thu, Jan 13, 2005 at 06:47:21PM +1100, Peter Jeremy wrote:
> On Wed, 2005-Jan-12 23:54:38 +1000, Stephen McKay wrote:
> >c) Make O_NONBLOCK be per file descriptor (like FD_CLOEXEC). Thus,
> >descriptors produced from dup() (for example) would have their own O_NONBLOCK
> >flag, just as two descriptors from separate open() calls have today.
> It might be useful to see what one of the POSIX experts think about this.
> FreeBSD, NetBSD, OpenBSD and Linux all explicitly state that dup(2)
> copies O_NONBLOCK (though Solaris 10 doesn't). It is reasonably likely
> that existing code relies on the documented behaviour and will therefore
> break when you move O_NONBLOCK from the file to the file descriptor.
POSIX states that the O_NONBLOCK flag is per open file description. File
descriptors created with dup(2), fork(2) or similar methods share the
same open file description, while new descriptors created with open(2)
Consequently, a POSIX-compliant implementation of O_NONBLOCK does not
solve the problem, as all descriptors to the terminal refer to the same
open file description. O_NONBLOCK is indeed unusable for descriptions
shared with other unknowing processes :(
More information about the freebsd-hackers