Problem with FIFO reads from multiple processes, not sure if bug or normal behavior

Anthony Barbachan (barbacha@Hinako.AMBusiness.com)
Mon, 9 Nov 1998 23:14:10 -0500


I am writing a program the uses FIFOs to receive commands from multiple
separate processes. After one process is finished sending data through the
FIFO and closes it, the select call always returns immediately after being
called, weather data is available or not. Causing my select based loop to
degrade to a polling function. The program still worked, but was looping
like crazy after the first process sent a command through the FIFO. After
some debugging I believe I narrowed the problem to the EOF flag being set on
the server's FIFO writing file descriptor and select returning when
encountering an EOF on the FIFO's descriptor even if all I was checking for
was available data. At first I figured this was normal behavior and started
searching for the function that I would need to call to clear the EOF flag.
The nearest that I could find was clearerr(). So I changed my code to use
stdio's file functions and used clearerr() to reset the EOF after a client
closes its end of the FIFO. This didn't work. I then tried using the
various seek functions to trick the system into reseting the EOF flag (as
they are suppose to do), no go, seeks aren't supported on FIFOs and pipes.
Finally in a moment of inspiration I decided to have the server open the
FIFO in O_RDWR mode. This worked, probably since the EOF is set only when
there are no more processes with a writing file descriptor open on the FIFO.
The problem is that my POSIX book says that opening a FIFO in O_RDWR mode is
undefined so I am not sure I am comfortable using this trick, especially
since the resulting program will also have to work under solaris. BTW, I
also used the O_NONBLOCK option to open the FIFO as the server is doing
other things and cannot wait for a client to open the FIFO for writing. Is
my O_RDWR trick the correct way to go? Is there a bug somewhere that is
causing the FIFO's read descriptor to not respond to clearerr()? Is the
FIFO's read descriptor erroneously set to EOF after a client is finished
with it? Is select erroneously returning early when there is a EOF on the
reading file descriptor even when select is being called only to check for
available data? Is there some other function that I am suppose to use to
clear the EOF flag?

- A. Barbachan

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/