Re: BUG: select(2) doesn't wait with O_RDONLY pipe

Alan Curry (pacman-kernel@cqc.com)
Mon, 4 Oct 1999 00:16:14 -0500 (EST)


Dave Broudy writes the following:
>The code that I produced this with is attached.

If you're going to send code, just send code, not MIME (with ^M's!)

And you only sent half the code: the reading half. Where's the writing half
of your test? I'll just guess that you did something like this:

mknod pipe p
./pipetest pipe &
echo foo > pipe

Well, what you're seeing is normal. At first, you opened the pipe for
reading. There is one reader and 0 writers. Nothing has been written to the
pipe, so it is not readable according to select, and read would block if you
tried it.

Then you opened it for writing and wrote something to it. There is 1 reader
and 1 writer, and there is stuff in the pipe. It's readable. Then you read
all the stuff out of it, and meanwhile, the writer went away. Back down to 1
reader and 0 writers.

When the numebr of writers on a pipe drops to 0, an EOF condition is
generated. That is a readable thing, so you are reading it. It's indicated by
read returning 0. And it will keep happening as long as there are readers and
no writers.

If you never want to see EOF on a pipe, you should keep an extra writer
around, probably by using an O_RDWR on your reading end. That's not a bug,
that's just how they work.

-
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/