kern/76144: poll doesn't set POLLHUP when FIFO is closed
Drazen Kacar
dave at fly.srk.fer.hr
Wed Jan 12 06:40:24 PST 2005
>Number: 76144
>Category: kern
>Synopsis: poll doesn't set POLLHUP when FIFO is closed
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Wed Jan 12 14:40:23 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator: Drazen Kacar
>Release: FreeBSD 5.3-RELEASE-p2 i386
>Organization:
Cardak ni na nebu, ni na zemlji
>Environment:
Observed with FreeBSD 5.2.1 and 5.3 kernels on i386.
>Description:
When the other end of a FIFO closes file descriptor, poll(2)
doesn't return with POLLHUP set in revents. Instead it keeps
waiting.
>How-To-Repeat:
The attached program demonstrates the problem. Compile the program
and run it. It another terminal (in the same directory) type:
echo foo >fifo
The program should output:
poll() returned 1
revents = 17
read() returned 4
and exit. (It does this on Linux and Solaris). Instead, on
FreeBSD, the output is:
poll() returned 1
revents = 1
read() returned 4
and the program doesn't exit.
>Fix:
Unknown.
--- fifo_poll.c begins here ---
#include <stdio.h>
#include <stdlib.h>
#include <poll.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/uio.h>
#include <fcntl.h>
int main()
{
int ret;
struct pollfd p[1];
char buf[256];
if (mkfifo("fifo", 0600))
{
perror("mkfifo");
exit(1);
}
p[0].fd = open("fifo", O_RDONLY | O_NONBLOCK);
if (p[0].fd < 0)
{
perror("open");
exit(1);
}
/* fcntl(p[0].fd, F_SETFL, 0); /* No change with this line. */
p[0].events = POLLIN;
do {
ret = poll(p, 1, -1);
printf("poll() returned %d\n", ret);
printf("revents = %d\n", (int)(p[0].revents));
if (p[0].revents & POLLIN)
{
ret = read(p[0].fd, buf, sizeof buf);
printf("read() returned %d\n", ret);
}
} while (!(p[0].revents & (POLLERR | POLLHUP | POLLNVAL)));
return 0;
}
--- fifo_poll.c ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list