[haiku-bugs] [Haiku] #7859: poll() on fd of an exited process returns wrong revents

  • From: "scgtrp" <trac@xxxxxxxxxxxx>
  • Date: Sat, 23 Jul 2011 11:36:47 -0000

#7859: poll() on fd of an exited process returns wrong revents
--------------------------+-------------------------
 Reporter:  scgtrp        |        Owner:  nobody
     Type:  bug           |       Status:  new
 Priority:  normal        |    Milestone:  R1
Component:  System/POSIX  |      Version:  R1/alpha3
 Keywords:                |   Blocked By:
 Blocking:                |  Has a Patch:  0
 Platform:  All           |
--------------------------+-------------------------
 The following test program runs properly on Linux, but does not exit on
 Haiku due to poll() setting revents to indicate that the fd is still valid
 and has readable data, even after the process exits:

 {{{
 #include <stdio.h>
 #include <poll.h>

 int main() {
         FILE* f = popen("/bin/bash -c 'for i in 1 2 3; do { echo $i; sleep
 1; }; done'", "r");
         printf("f=%p\n", f);
         int fd = fileno(f);
         printf("fd=%d\n", fd);

         struct pollfd pfd;
         pfd.fd = fd;
         pfd.events = POLLIN | POLLRDBAND;

         char buffer[80];

         while (1) {
                 int rv = poll(&pfd, 1, 500);
                 printf("rv=%d\n", rv);
                 if (rv == 0)
                         continue;
                 if (rv < 0)
                         break;
                 printf("events=%08x revents=%08x\n", pfd.events,
 pfd.revents);
                 if ((pfd.events & pfd.revents) == 0)
                         break;

                 fgets(buffer, 79, f);
                 printf("output: %s", buffer);
         }

         return 0;
 }
 }}}

-- 
Ticket URL: <http://dev.haiku-os.org/ticket/7859>
Haiku <http://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: