apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mladen Turk <mt...@apache.org>
Subject poll/select with revents == 0
Date Mon, 18 Jan 2010 06:32:05 GMT

I just noticed a wired case where poll returns an signalled descriptor
event with revents == 0.
This can happen regularly with pipes if you create two separate pipes
for stdout and stderr for redirected process.

E.g. redirecting '/bin/sh ls' with two set of pipes and doing poll on
both stderr and stdout will cause the poll to return 1 but the returned
pollfd will have revents == 0 for stdout
(because sh cannot execute binary file).
I suppose this should actually be POLLHUP cause the next read will
return zero for that descriptor (meaning EOF).

Looking at our poll code I see that we just skip descriptors
for which poll returned as signaled but with revents == 0.
I wonder weather this is a correct approach, cause
1. I cannot find any reference in poll man pages
    what the revents == 0 means.
2. This is potential infinite loop because one will end up calling
    poll with SUCCESS and zero descriptors returned.

I have a small test case that proves this issue
(just a plain code, no APR)
$ gcc testpoll.c -o testpoll
$ ./testpoll /bin/sh ls

... and watch for the result

It's wired that it doesn't return revents == 0 all the times.
Tested on Linux (Fedora 12) and Mac OSX 10.6
Same happens if you modify the code to use select instead poll.

Anyone knows what might be the technical background
for such a behaviour?

Also is just skipping those descriptors and never reporting
that situation back in our code correct approach?


View raw message