mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gereon Steffens <gereon.steffens@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: poll() returns EINVAL
Date: Fri, 26 Aug 2005 17:25:48 +0200	[thread overview]
Message-ID: <54315475050826082547323146@mail.gmail.com> (raw)

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

                 reply	other threads:[~2005-08-26 15:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54315475050826082547323146@mail.gmail.com \
    --to=gereon.steffens@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome