From ab@seerajeane.astralblue.net  Tue Aug 21 17:25:59 2007
Return-Path: <ab@seerajeane.astralblue.net>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id E307316A420
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 21 Aug 2007 17:25:59 +0000 (UTC)
	(envelope-from ab@seerajeane.astralblue.net)
Received: from purple.the-7.net (purple.the-7.net [IPv6:2001:470:1f01:622:230:48ff:fe23:4c67])
	by mx1.freebsd.org (Postfix) with ESMTP id C667013C48D
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 21 Aug 2007 17:25:59 +0000 (UTC)
	(envelope-from ab@seerajeane.astralblue.net)
Received: from seerajeane.astralblue.net (seerajeane.astralblue.net [IPv6:2001:470:1f01:623:2e0:81ff:fe51:1e73])
	by purple.the-7.net (8.13.8/8.13.8) with ESMTP id l7LHPnQo073763
	(version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=OK)
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 21 Aug 2007 10:25:49 -0700 (PDT)
	(envelope-from ab@seerajeane.astralblue.net)
Received: from seerajeane.astralblue.net (seerajeane.astralblue.net [127.0.0.1])
	by seerajeane.astralblue.net (8.14.1/8.14.1) with ESMTP id l7LHPr9c085027
	(version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=OK)
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 21 Aug 2007 10:25:53 -0700 (PDT)
	(envelope-from ab@seerajeane.astralblue.net)
Received: (from ab@localhost)
	by seerajeane.astralblue.net (8.14.1/8.14.1/Submit) id l7LHLoJn084887;
	Tue, 21 Aug 2007 10:21:50 -0700 (PDT)
	(envelope-from ab)
Message-Id: <200708211721.l7LHLoJn084887@seerajeane.astralblue.net>
Date: Tue, 21 Aug 2007 10:21:50 -0700 (PDT)
From: "Eugene M. Kim" <freebsd.org@ab.ote.we.lv>
Reply-To: "Eugene M. Kim" <freebsd.org@ab.ote.we.lv>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: rdesktop(1) hangs in a tight loop upon sound device close
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         115692
>Category:       ports
>Synopsis:       net/rdesktop(1) hangs in a tight loop upon sound device close
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    obrien
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 21 17:30:01 GMT 2007
>Closed-Date:    Fri Aug 24 06:11:48 GMT 2007
>Last-Modified:  Fri Aug 24 06:11:48 GMT 2007
>Originator:     Eugene M. Kim
>Release:        FreeBSD 7.0-CURRENT i386
>Organization:
AstralBlue
>Environment:
System: FreeBSD seerajeane.astralblue.net 7.0-CURRENT FreeBSD 7.0-CURRENT #1: Sat Jul 28 09:00:00 PDT 2007 ab@seerajeane.astralblue.net:/home/FreeBSD/build/MAIN/obj/home/FreeBSD/build/MAIN/src/sys/PL-SEERAJEANE i386
>Description:
Upon server-initiated closure of the sound device, rdesktop(1) hangs in
a tight loop if the sound packet buffer is not empty.  This usually
occurs after a long playback, and is indicated by an endless stream of
"ERROR: select: Bad file descriptor" messages on stderr.
>How-To-Repeat:
Run rdesktop with -r sound:local, and play an MP3 file for about 30
seconds then stop playback.
>Fix:
Apply the following patch, which forcibly empties the sound packet buffer
after closing the sound device.
--- patch-rdpsnd_oss.c begins here ---
--- rdpsnd_oss.c	2007-08-20 23:20:40.000000000 -0700
+++ rdpsnd_oss.c.new	2007-08-20 23:21:51.000000000 -0700
@@ -51,6 +51,35 @@
 } packet_queue[MAX_QUEUE];
 static unsigned int queue_hi, queue_lo;
 
+/** Frees the first audio packet in the queue (that is, packet_queue[queue_lo]),
+ * sending a completion notification back to the server.
+ *
+ * @return True if the packet queue has become empty; False otherwise.&nbsp;
+ *
+ * If the packet queue is not empty, queue_lo will point at the next packet to
+ * play.
+ */
+static BOOL
+packet_done(void)
+{
+	struct audio_packet *packet = &packet_queue[queue_lo++];
+	queue_lo %= MAX_QUEUE;
+	rdpsnd_send_completion(packet->tick, packet->index);
+	free(packet->s.data);
+	return (queue_lo == queue_hi);
+}
+
+/** Discards all audio packets queued, sending completion notifications back to
+ * the server as necessary.
+ */
+static void
+clear_queue(void)
+{
+	while (queue_lo != queue_hi)
+		packet_done();
+	g_dsp_busy = False;
+}
+
 BOOL
 wave_out_open(void)
 {
@@ -74,6 +103,7 @@
 wave_out_close(void)
 {
 	close(g_dsp_fd);
+	clear_queue();
 }
 
 BOOL
@@ -277,9 +307,7 @@
 
 		if (elapsed >= (duration * 85) / 100)
 		{
-			rdpsnd_send_completion(packet->tick, packet->index);
-			free(out->data);
-			queue_lo = (queue_lo + 1) % MAX_QUEUE;
+			packet_done();
 			started = False;
 		}
 		else
--- patch-rdpsnd_oss.c ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->obrien 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Wed Aug 22 00:08:40 UTC 2007 
Responsible-Changed-Why:  
Over to maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=115692 
State-Changed-From-To: open->feedback 
State-Changed-By: obrien 
State-Changed-When: Thu Aug 23 20:42:07 UTC 2007 
State-Changed-Why:  
Hi Eugene, 
Have you submitted this patch to the rdesktop project on SourceForge? 
If so, I'll commit it to the FreeBSD port.  Otherwise, could you please 
report the bug?  I'm a little worried your patch is large enough that 
it could make the next upgrade harder. 
-- David 

http://www.freebsd.org/cgi/query-pr.cgi?pr=115692 

From: "Eugene M. Kim" <freebsd.org@ab.ote.we.lv>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/115692: net/rdesktop(1) hangs in a tight loop upon sound
 device close
Date: Thu, 23 Aug 2007 15:35:48 -0700

 Yes, there was already a bug filed for this, to which I submitted the 
 same patch.
 
 https://sourceforge.net/tracker/?func=detail&atid=381347&aid=1695146&group_id=24366
 
 is the bug report.
 
 Thank you,
 Eugene
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/115692: commit references a PR
Date: Thu, 23 Aug 2007 23:54:04 +0000 (UTC)

 obrien      2007-08-23 23:53:59 UTC
 
   FreeBSD ports repository
 
   Added files:
     net/rdesktop/files   patch-rdpsnd_oss.c 
   Log:
   Upon server-initiated closure of the sound device, rdesktop(1) hangs in
   a tight loop if the sound packet buffer is not empty.  This usually
   occurs after a long playback, and is indicated by an endless stream of
   "ERROR: select: Bad file descriptor" messages on stderr.
   
   Fix: forcibly empty the sound packet buffer after closing the sound device.
   
   PR:             115692
   Submitted by:   "Eugene M. Kim" <freebsd.org@ab.ote.we.lv>
   
   Revision  Changes    Path
   1.1       +57 -0     ports/net/rdesktop/files/patch-rdpsnd_oss.c (new)
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: feedback->closed 
State-Changed-By: obrien 
State-Changed-When: Fri Aug 24 06:11:11 UTC 2007 
State-Changed-Why:  
Submitter sent patch up-stream, and I committed to /usr/ports. 

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