Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Dec 1998 20:21:18 +1100
From:      Bruce Evans <bde@zeta.org.au>
To:        cejkar@dcse.fee.vutbr.cz, freebsd-current@FreeBSD.ORG
Subject:   Re: mkfifo()/select() & O_RDONLY serious bug?
Message-ID:  <199812110921.UAA28085@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>I have prepared small testing program (listed at the end) with mkfifo()
>and select() calls. Fifo is opened as O_RDONLY or O_RDWR with O_NONBLOCK.
>On FreeBSD 3.0-CURRENT, its behavior is different from other systems.
>I think it is serious bug: select() returns that there is ready file
>descriptor but descriptor is not ready in fact. I'm right?

I think it's a feature :-).  The descriptor is ready for reading.
read() will succeed and return 0 (EOF) because the mode is O_NONBLOCK and
there are no writers.  This is as specified by POSIX.1.  POSIX.1 doesn't
specify select(), and the FreeBSD implementation is simply that select()
returns success if read() would succeed immediately.

>Tested on systems:
>	FreeBSD 3.0-CURRENT
>	FreeBSD 2.2.7
>	Solaris 2.6
>	Unixware 2.1
>	Linux Debian 2.0

I think your program works like you want in 2.2.7 because read() on a
fifo is broken in 2.2.7 -- it sometimes blocks in O_NONBLOCK mode, and
select() just folliows read().  IIRC, this only affects the case where
there have never been any writers.

In Linux, I thought that this was related to the FIFO_SUNOS_BRAINDAMAGE
option -- if this option is configuted, select() on fifos is specially
broken to behave differently from select() on nameless pipes.  However,
`#undef FIFO_SUNOS_BRAINDAMAGE' seems to be the default in linux-2.1.128,
and your program works like you want there.

I don't know about the other systems.

>Another bug: On FreeBSD systems I must use "#include <string.h>" for
>FD_ZERO() because of bzero() function. Yes? (If not, we need to fix
>manual page for select(2) about needed includes.)

Linux accidentially (?) avoids this problem by using an asm statement.
It would be better to use memset().

>Results with "#define MODE O_RDWR": (It looks well.)

This works because O_RDWR gives a writer, so the read descriptor is
never ready.

Bruce

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



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