[lkml]   [2005]   [Aug]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Subjectpoll() returns EINVAL

under what appears to me as weird circumstances, poll() returns EINVAL
where I belive it shouldn't. Here's an example program that
demonstrates the problem both on kernel 2.4 and 2.6 machines:

#include <sys/poll.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define MAX 1025
#define MOD 250

int main(int argc, char**argv)
struct pollfd pfd[MAX] = { { 0 } };

int i, rc;

for (i=0; i<MAX; ++i)
int fd;

fd = dup(1);

pfd[i].fd = fd;
pfd[i].events = POLLOUT;
pfd[i].revents = 0;
printf("%d fd: %d\n", i, fd);

if (i % MOD == 0)
/* put same fd into set with a check for reading */
pfd[i].fd = fd;
pfd[i].events = POLLIN;
pfd[i].revents = 0;
printf("%d fd: %d\n", i, fd);


rc = poll(pfd, MAX, 0);
printf("poll rc %d errno %d %s\n", rc, errno, strerror(errno));

return 0;

Run this program after the number for file descriptors per process has
been increased to more than 1024, e.g. using "ulimit -n 2000".

Even more weird is the fact than when MAX is defined as 1024 or less,
the failure never happens. If MOD is changed so that less than 4
fds are in the set, poll() works fine also.

Am I doing something wrong? Why does poll choke on such duplicate fd
to be checked, and why does it do this only when the fd list is longer
than 1024 entries?

Thanks for any insights,

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-08-26 17:28    [W:0.026 / U:1.388 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site