From dave@globalnet.hr  Wed Jan 12 14:34:14 2005
Return-Path: <dave@globalnet.hr>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 7CC3616A4D9
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Jan 2005 14:34:14 +0000 (GMT)
Received: from kyle.globalnet.hr (kyle.globalnet.hr [213.149.32.24])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 413B043D45
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Jan 2005 14:34:13 +0000 (GMT)
	(envelope-from dave@globalnet.hr)
Received: from mail.globalnet.hr (cartman.globalnet.hr [213.149.32.10])
	by kyle.globalnet.hr (8.12.3/8.12.3/Debian-7.1) with ESMTP id j0CEY9S1005542
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Jan 2005 15:34:11 +0100
Received: (qmail 28867 invoked from network); 12 Jan 2005 14:34:08 -0000
Received: from r1.globalnet.hr (HELO vertigo.globalnet.hr) ([213.149.32.1])
          (envelope-sender <dave@globalnet.hr>)
          by 0 (qmail-ldap-1.03) with SMTP
          for <FreeBSD-gnats-submit@freebsd.org>; 12 Jan 2005 14:34:08 -0000
Received: from vertigo.globalnet.hr (localhost [127.0.0.1])
	by vertigo.globalnet.hr (8.13.1/8.13.1) with ESMTP id j0CEZtUB089565
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Jan 2005 15:35:55 +0100 (CET)
	(envelope-from dave@globalnet.hr)
Received: (from dave@localhost)
	by vertigo.globalnet.hr (8.13.1/8.13.1/Submit) id j0CEZtH3089564
	for FreeBSD-gnats-submit@freebsd.org; Wed, 12 Jan 2005 15:35:55 +0100 (CET)
	(envelope-from dave@globalnet.hr)
Message-Id: <20050112143555.GA89550@vertigo.globalnet.hr>
Date: Wed, 12 Jan 2005 15:35:55 +0100
From: Drazen Kacar <dave@fly.srk.fer.hr>
Reply-To: Drazen Kacar <dave@fly.srk.fer.hr>
To: FreeBSD-gnats-submit@freebsd.org
Subject: poll doesn't set POLLHUP when FIFO is closed
X-Send-Pr-Version: 3.113

>Number:         76144
>Category:       kern
>Synopsis:       [fifo] poll doesn't set POLLHUP when FIFO is closed
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 12 14:40:23 GMT 2005
>Closed-Date:    Tue Nov 13 20:51:21 UTC 2012
>Last-Modified:  Tue Nov 13 20:51:21 UTC 2012
>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:
State-Changed-From-To: open->feedback 
State-Changed-By: arundel 
State-Changed-When: Mon Sep 6 23:52:19 UTC 2010 
State-Changed-Why:  
I ran the test you mentioned in this PR under a very recent HEAD and got the 
following output with 'fifo_poll' exiting (not looping): 

poll() returned 1 
revents = 1 
read() returned 4 
poll() returned 1 
revents = 17 
read() returned 0 

Recompiling and running 'fifo_poll' under Linux returned the same result. Could 
you check, if this issue still exists in a supported branch? 
Thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=76144 
State-Changed-From-To: feedback->closed 
State-Changed-By: eadler 
State-Changed-When: Tue Nov 13 20:51:20 UTC 2012 
State-Changed-Why:  
Feedback timeout. Please email me and I will reopen if needed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=76144 
>Unformatted:
