Is it OK to poll() a device file descriptor
Elazar Leibovich
elazarl at gmail.com
Tue Jun 18 17:43:59 IDT 2013
Try to open /dev/null, and then to poll the file descriptor. Neither in the
man page nor in the standard I see anything preventing you to poll on
/dev/null, yet, it does not work on Mac OS X. You get a POLLNVAL.
Run the following:
https://gist.github.com/elazarl/5805848
#include <stdio.h>
#include <poll.h>
#include <fcntl.h>
int main() {
int fd = open("/dev/null", O_WRONLY);
struct pollfd pollfds = { fd, POLLOUT, 0 };
if (fd < 0) {
perror("open");
return 1;
}
if (poll(&pollfds, 1, -1) < 0) {
perror("poll");
return 2;
}
if (pollfds.revents == POLLNVAL) {
puts("huh? why poll({/dev/null, POLLOUT, 0}, 1) returns POLLNVAL?");
}
if (pollfds.revents == POLLOUT) {
puts("working as expected");
}
return 0;
}
Is there anything I'm missing? Or is it a real vaguely implemented
corner of the standard.
If it is, I'll be glad to see a list of supported/unsupported platforms,
as well as list of other corner cases (for instance, POLLHUP may or
may be received on EOF).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20130618/87b7a14c/attachment.html>
More information about the Linux-il
mailing list