public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "teodori.serge at hotmail dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sources.redhat.com
Subject: [Bug libc/13660] New: poll wrong revents returned
Date: Fri, 03 Feb 2012 19:14:00 -0000	[thread overview]
Message-ID: <bug-13660-131@http.sourceware.org/bugzilla/> (raw)

http://sourceware.org/bugzilla/show_bug.cgi?id=13660

             Bug #: 13660
           Summary: poll wrong revents returned
           Product: glibc
           Version: 2.14
            Status: NEW
          Severity: critical
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: teodori.serge@hotmail.com
    Classification: Unclassified


Hello,
poll() is not returning the right events. If socket has data to read, POLLIN is
set, but if socket is closed or shutdown it also sets POLLIN? It should
normally be POLLERR POLLHUP or POLLNVAL, at least not POLLIN.

Ex.:

int prc = 0;
struct pollfd pfd;
while(prc != -1){
 pfd.fd = connectedsocket;
 pfd.events = POLLIN;
 prc = poll(&pfd, 1, 1000);
 if(prc == -1){
  perror("poll");
 }else if(prc == 0){
  printf("timeout");
 }else if(prc == 1 && pfd.revents == POLLIN){
  recv(pfd.fd, buff, sizeof(buff), 0);
  printf("data: %s\n", buff);
 }else if(prc == 1 && pfd.revents != POLLIN){
  close(pfd.fd);
  printf("socket closed\n");
  prc = -1;
 }
}

Output:
timeout
timeout
timeout
data: Hello //peer send data
timeout
timeout
timeout
data: // peer closed or shutdown socket -> poll is heating up 100% CPU
data:
data:
data:

This is the case on Ubuntu and on my own linux from scratch (linux-3.2.2 +
glibc-2.14.1 compiled with gcc-4.6.2 and the linux-3.2.2 headers).
I doubt that it could be and build error, because I tried it on i386 and x86
with different.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


             reply	other threads:[~2012-02-03 19:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-03 19:14 teodori.serge at hotmail dot com [this message]
2012-02-03 19:47 ` [Bug libc/13660] " drepper.fsp at gmail dot com
2012-02-04  0:08 ` bugdal at aerifal dot cx
2012-02-09  0:19 ` teodori.serge at hotmail dot com
2012-02-09  0:42 ` bugdal at aerifal dot cx
2012-02-09 22:42 ` teodori.serge at hotmail dot com
2012-02-10  1:29 ` bugdal at aerifal dot cx
2014-06-13 14:09 ` fweimer at redhat dot com

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=bug-13660-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sources.redhat.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).