From patchwork Mon Jun 2 19:41:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Goode X-Patchwork-Id: 4285091 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B32B3BEEA7 for ; Tue, 3 Jun 2014 05:18:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C0DC32024D for ; Tue, 3 Jun 2014 05:18:45 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 4774B2021F for ; Tue, 3 Jun 2014 05:18:44 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5D7BA265540; Tue, 3 Jun 2014 07:18:42 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, NO_DNS_FOR_FROM, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 175A4265262; Tue, 3 Jun 2014 07:18:32 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id E4C492651B7; Mon, 2 Jun 2014 21:41:35 +0200 (CEST) Received: from mail-yh0-f43.google.com (mail-yh0-f43.google.com [209.85.213.43]) by alsa0.perex.cz (Postfix) with ESMTP id 3ECD42651B7 for ; Mon, 2 Jun 2014 21:41:27 +0200 (CEST) Received: by mail-yh0-f43.google.com with SMTP id v1so4248642yhn.2 for ; Mon, 02 Jun 2014 12:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=gpJfTw1nB8opPVg0aOLD5cPfWK3LAeJSI6XnniCLhiM=; b=jCHFcZe1sMbS7BVx9nBLkjoYCT60+1GnaaD3FJBACEnh2Z3c//ghG+4oZk36OQTd2v 5vyRnavUoburdedkJhtoXMoTmKsrGSb5/vQomhzmObOY2RnmDCY35uzdJpI6QFs2GcMi uaxdq1U41OfHQ9GaeDYiYeKxO95jcdyOm2DtIW2dTlBUpPo5coOs0Kca+Zv77ZybjUHX su7dXpy9SOr7Ng+KMkizPLg/goaKUD/AkkA2gNL5ihJnuyK1l8shnI6aWF93NWXTztMx WUgL5xvdkEjvUwPnNtBMBC4IdwM5bAmxdfXE7Yj8HnyU7h9+Gu98ZPEHPJx3HiSHULf3 vTAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=gpJfTw1nB8opPVg0aOLD5cPfWK3LAeJSI6XnniCLhiM=; b=R3k1g+e+6lGm8E+kIoFm30arQEcdRjh9ykjcnicAEc6M91sfN3XB5NANDUDTpZvjCM deJRwyzoyrDUBXndNSLrTdrpeS8Mr94RfwAPiEqSQ1l7vDSDA+o04/Ttn8XvWy6uTwNH vaOyQlx8Ic6DeIZqtngREBq0y44tesz8xbX6SUnFrmpc6MHkM+8b6sjuy/gdACCFIneX y3UsIBvqsNNl+Na6SGoczjQZ1GMf/a0tn80936v7piuDoBTMxyfqylUGR87pgQNuUvvX qjiZ3TM1EgKQV8re6Eipar03jA965tGPQMVX6/J8cq6SczdvgpeNFKfLcx3j4XoACYiB NIDQ== X-Gm-Message-State: ALoCoQkXv5uV6uAB8WqD5pBPi/yO2zgehM2lp480pfs3Vm09renYeCic0hbccqahgbIBsOJubkPr X-Received: by 10.236.129.227 with SMTP id h63mr6448535yhi.148.1401738085825; Mon, 02 Jun 2014 12:41:25 -0700 (PDT) Received: from wpg-ubiq154.hot.corp.google.com (wpg-ubiq154.hot.corp.google.com [172.24.166.195]) by mx.google.com with ESMTPSA id b32sm21855873yhi.47.2014.06.02.12.41.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Jun 2014 12:41:25 -0700 (PDT) From: Adam Goode To: patch@alsa-project.org Date: Mon, 2 Jun 2014 15:41:22 -0400 Message-Id: <1401738082-28488-1-git-send-email-agoode@google.com> X-Mailer: git-send-email 1.9.1.423.g4596e3a X-Mailman-Approved-At: Tue, 03 Jun 2014 07:18:29 +0200 Cc: Adam Goode , alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH - seq 1/1] ALSA: seq: Continue broadcasting events to ports if one of them fails X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Sometimes PORT_EXIT messages are lost when a process is exiting. This happens if you subscribe to the announce port with client A, then subscribe to the announce port with client B, then kill client A. Client B will not see the PORT_EXIT message because client A's port is closing and is earlier in the announce port subscription list. The for each loop will try to send the announcement to client A and fail, then will stop trying to broadcast to other ports. Killing B works fine since the announcement will already have gone to A. The CLIENT_EXIT message does not get lost. How to reproduce problem: *** termA $ aseqdump -p 0:1 0:1 Port subscribed 0:1 -> 128:0 *** termB $ aseqdump -p 0:1 *** termA 0:1 Client start client 129 0:1 Port start 129:0 0:1 Port subscribed 0:1 -> 129:0 *** termB 0:1 Port subscribed 0:1 -> 129:0 *** termA ^C *** termB 0:1 Client exit client 128 <--- expected Port exit as well (before client exit) Signed-off-by: Adam Goode diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c index 9ca5e64..f9b5315 100644 --- a/sound/core/seq/seq_clientmgr.c +++ b/sound/core/seq/seq_clientmgr.c @@ -660,7 +660,7 @@ static int deliver_to_subscribers(struct snd_seq_client *client, int atomic, int hop) { struct snd_seq_subscribers *subs; - int err = 0, num_ev = 0; + int err = 0, sticky_err = 0, num_ev = 0; struct snd_seq_event event_saved; struct snd_seq_client_port *src_port; struct snd_seq_port_subs_info *grp; @@ -685,8 +685,12 @@ static int deliver_to_subscribers(struct snd_seq_client *client, subs->info.flags & SNDRV_SEQ_PORT_SUBS_TIME_REAL); err = snd_seq_deliver_single_event(client, event, 0, atomic, hop); - if (err < 0) - break; + if (err < 0) { + /* save first error that occurs and continue */ + if (!sticky_err) + sticky_err = err; + continue; + } num_ev++; /* restore original event record */ *event = event_saved; @@ -697,7 +701,7 @@ static int deliver_to_subscribers(struct snd_seq_client *client, up_read(&grp->list_mutex); *event = event_saved; /* restore */ snd_seq_port_unlock(src_port); - return (err < 0) ? err : num_ev; + return (sticky_err < 0) ? sticky_err : num_ev; } @@ -709,7 +713,7 @@ static int port_broadcast_event(struct snd_seq_client *client, struct snd_seq_event *event, int atomic, int hop) { - int num_ev = 0, err = 0; + int num_ev = 0, err = 0, sticky_err = 0; struct snd_seq_client *dest_client; struct snd_seq_client_port *port; @@ -724,14 +728,18 @@ static int port_broadcast_event(struct snd_seq_client *client, err = snd_seq_deliver_single_event(NULL, event, SNDRV_SEQ_FILTER_BROADCAST, atomic, hop); - if (err < 0) - break; + if (err < 0) { + /* save first error that occurs and continue */ + if (!sticky_err) + sticky_err = err; + continue; + } num_ev++; } read_unlock(&dest_client->ports_lock); snd_seq_client_unlock(dest_client); event->dest.port = SNDRV_SEQ_ADDRESS_BROADCAST; /* restore */ - return (err < 0) ? err : num_ev; + return (sticky_err < 0) ? sticky_err : num_ev; } /* @@ -741,7 +749,7 @@ static int port_broadcast_event(struct snd_seq_client *client, static int broadcast_event(struct snd_seq_client *client, struct snd_seq_event *event, int atomic, int hop) { - int err = 0, num_ev = 0; + int err = 0, sticky_err = 0, num_ev = 0; int dest; struct snd_seq_addr addr; @@ -760,12 +768,16 @@ static int broadcast_event(struct snd_seq_client *client, err = snd_seq_deliver_single_event(NULL, event, SNDRV_SEQ_FILTER_BROADCAST, atomic, hop); - if (err < 0) - break; + if (err < 0) { + /* save first error that occurs and continue */ + if (!sticky_err) + sticky_err = err; + continue; + } num_ev += err; } event->dest = addr; /* restore */ - return (err < 0) ? err : num_ev; + return (sticky_err < 0) ? sticky_err : num_ev; }