lkml.org 
[lkml]   [2005]   [Aug]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectpoll() returns EINVAL
Hi,

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 */
++i;
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
"duplicate"
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,

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

\
 
 \ /
  Last update: 2005-08-26 17:28    [W:0.037 / U:0.172 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site