From nobody@FreeBSD.org  Wed Nov 30 20:14:15 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 45E6916A424
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 30 Nov 2005 20:14:15 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 3317643D81
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 30 Nov 2005 20:14:07 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id jAUKE6Bj095288
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 30 Nov 2005 20:14:06 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id jAUKE6v1095287;
	Wed, 30 Nov 2005 20:14:06 GMT
	(envelope-from nobody)
Message-Id: <200511302014.jAUKE6v1095287@www.freebsd.org>
Date: Wed, 30 Nov 2005 20:14:06 GMT
From: Yuri <yuri@tsoft.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: kevent hangs on second wait for /dev/dsp
X-Send-Pr-Version: www-2.3

>Number:         89775
>Category:       kern
>Synopsis:       [kqueue] [hang] kevent hangs on second wait for /dev/dsp
>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 Nov 30 20:20:03 GMT 2005
>Closed-Date:    
>Last-Modified:  Mon Apr 14 19:57:11 UTC 2008
>Originator:     Yuri
>Release:        5.4 stable
>Organization:
N/A
>Environment:
FreeBSD xxx.xxx.xxx 5.4-RELEASE-p3 FreeBSD 5.4-RELEASE-p3 #0: Thu Jul  7 22:03:34 PDT 2005     xxx@xxx.xxx.xxx:/usr/src/sys/i386/compile/GENERIC  i386
>Description:
If kernel queue has sound device /dev/dsp in it kevent only being triggered once.
Second call to it hangs although data is obviously continuously available from soundcard.

relevant dmesg messages describing the card are:
pcm0: <Creative EMU10K1> port 0xdc00-0xdc1f irq 17 at device 6.0 on pci0
pcm0: <TriTech TR28602 AC97 Codec>

>How-To-Repeat:
compile and run the following code:
----code------
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
                                                                                                                                                                                                     
#include <sys/types.h>
#include <sys/event.h>
                                                                                                                                                                                                     
                                                                                                                                                                                                     
int
main(int argc, char *argv[]) {
  int res, kq;
  int dsp;
                                                                                                                                                                                                     
                                                                                                                                                                                                     
  kq = kqueue();
  printf("kqueue returned %i\n", kq);
                                                                                                                                                                                                     
  char buf[1024];
                                                                                                                                                                                                     
  dsp = open("/dev/dsp", O_RDONLY);
                                                                                                                                                                                                     
  struct kevent kev;
  EV_SET(&kev, dsp, EVFILT_READ, EV_ADD, 0/*fflags*/, 0/*data*/, NULL);
                                                                                                                                                                                                     
  struct kevent result_events[256];
                                                                                                                                                                                                     
  // 1
  printf(">kevent1\n");
  res = kevent(kq,
     &kev, 1,
     &result_events[0], 256,
     NULL
  );
  printf("<kevent1 returned %i\n", res);
                                                                                                                                                                                                     
  printf(">read returned %i\n", res);
  res = read(dsp, buf, sizeof(buf));
  printf("<read returned %i\n", res);
                                                                                                                                                                                                     
  // 2
  printf(">kevent2\n");
  res = kevent(kq,
     NULL/*&kev*/, 0,
     &result_events[0], 256,
     NULL
  );
  printf("<kevent2 returned %i\n", res);
                                                                                                                                                                                                     
  //
  close(dsp);
                                                                                                                                                                                                     
  return (0);
}

>Fix:
N/A
>Release-Note:
>Audit-Trail:

From: Yuri <yuri@tsoft.com>
To: bug-followup@FreeBSD.org, yuri@tsoft.com
Cc:  
Subject: Re: kern/89775: [kevent] [hang] kevent hangs on second wait for /dev/dsp
Date: Wed, 30 Nov 2005 22:45:42 -0800

 Moreover, if right after open I make FD async with these 2 lines:
 
 int on = 1;
 ioctl(dsp, FIONBIO, &on);
 
 the first 'read' call fails with 'Resource temporarily unavailable' 
 error (right after kevent returns that data is available).
 
 Yuri
 
>Unformatted:
