poll() returns EINVAL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux