From owner-freebsd-current Fri Dec 11 01:21:42 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id BAA09926 for freebsd-current-outgoing; Fri, 11 Dec 1998 01:21:42 -0800 (PST) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.26.10.9]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id BAA09919 for ; Fri, 11 Dec 1998 01:21:39 -0800 (PST) (envelope-from bde@godzilla.zeta.org.au) Received: (from bde@localhost) by godzilla.zeta.org.au (8.8.7/8.8.7) id UAA28085; Fri, 11 Dec 1998 20:21:18 +1100 Date: Fri, 11 Dec 1998 20:21:18 +1100 From: Bruce Evans Message-Id: <199812110921.UAA28085@godzilla.zeta.org.au> To: cejkar@dcse.fee.vutbr.cz, freebsd-current@FreeBSD.ORG Subject: Re: mkfifo()/select() & O_RDONLY serious bug? Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG >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 " 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