Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4095388ybz; Mon, 20 Apr 2020 15:41:42 -0700 (PDT) X-Google-Smtp-Source: APiQypJNWlue2YG5sukxIlJ/O7eiKXlrAtJmgyRACDDKSVtP+65QD4NNocuEQ4ygpTviSxMepvub X-Received: by 2002:a05:6402:3129:: with SMTP id dd9mr3310277edb.121.1587422502725; Mon, 20 Apr 2020 15:41:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587422502; cv=none; d=google.com; s=arc-20160816; b=iIWhkTYZV70t/2oVXeeLp9Fpmf55GNNkZOLSwSE7pb9DLmB64UuiNqlJGQakNH6eOF jtPMqaquqLGjC7Aq3eV5zB/y8u4YOwarefzDgy9p/G807SImgxZZD7Z2BPTt3xLHkJjm SEGyEIVGCuKk7Y8SpRV6FUMBKg/lOYupIaEZ8nbnJdHKW5CF+sjwwWkHpui8GHn4/GW3 lFx5kL0Pqxmjvtl+TNOzWg2Z0wEoPGl4V1yg8foGqN067bqWC4mfiuISd2senawnlu+I CLkmNIOiLujjflJeIvYZF3Dq6WsMROIqWPfgFxZnMGZOvg4sXHIiHEq2K9IC9oHSx+qT XOtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=04q0PmHXOuzQxjLLYpnWrSrywgKTNWy6DTSnBtlY6SQ=; b=q31IrnASVrKtEkiVGVK8z1V2Q85asUwFv7B3oo7e993d8Vc7KhfDJU24uH3YR30Tta b9UAE3mYOieYjlSZUtV7PSnRm23Nv/YAryJI2cX8aHQGreUMM2bYxXLcK57y8lgmseB3 fFf9SvQnQP3IwFEqAmdTSaSE81yTDH4bvRiu5ZS5q7Z7qKZJKxyTEP0b8uCnM0ZsoAEZ dJk0coRNGYW37NCkI9hypbneZnVAszHOvA7todYDXAom67oLoXhaml+KjZpSjzkASm0X lhCSe4v8Yp9tiK08Asrlc6wGvqzRVYkpnJZjL5YGZIo4gEFj14nLy1Zu24Gnyu/1gHPR MP7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GHKsaudD; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j24si341370ejb.58.2020.04.20.15.40.56; Mon, 20 Apr 2020 15:41:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GHKsaudD; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726398AbgDTWi4 (ORCPT + 99 others); Mon, 20 Apr 2020 18:38:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726006AbgDTWi4 (ORCPT ); Mon, 20 Apr 2020 18:38:56 -0400 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0006C061A0C for ; Mon, 20 Apr 2020 15:38:55 -0700 (PDT) Received: by mail-ot1-x343.google.com with SMTP id b13so9636825oti.3 for ; Mon, 20 Apr 2020 15:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=04q0PmHXOuzQxjLLYpnWrSrywgKTNWy6DTSnBtlY6SQ=; b=GHKsaudD8rhUwxEpzXc0c0HUcypwKLMmUwnK0FVxIBz0k2UvFUVFw03amtnyPU2OBX 2H+oMXIMHa5Q5dui0T+6n2QLTFnonC/93XkIaFWN7KRRQXq6yTZafActb2QzFZqtQJZM 4NzqYp2gzDgCLWvMt0al0zRLPAyKp+wzI86lYtRopJNS7LZc5lTkKeLRu4rmHWCt6xJs J06XgQct4eqfZP7LL7cQLu0DJeARaR2PQH759R7Pn0AQE35+WawgLtV8qJUsGgb1BjMX rPuXbU4i4iIJU+fP/mLCAN/uBTMVDPhtdI7DKAvp5p2Jt3d/2l+ajU/3wDjVDHwqhj1A YZhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=04q0PmHXOuzQxjLLYpnWrSrywgKTNWy6DTSnBtlY6SQ=; b=A72CImX6taViysLSV8CH+8ZXJxIq/6INjSix7kiHbTbklor+gQnQWwZkOThcCa9nja D3AzC4r96vVJuuEQRJAsJ3Rzz0xBmUjQtFGi6jabiad9UJN1JYPdiHDAp1ZNA0pzqNx4 WLZ3tKypQUfBcQHgPAKy8V7CGtpIl093Nu6lXp17PqyuYpfJJ/Ov//DIJtBsZevvrcNJ PMclYsl/u7oBeisWcgdejq64csnR2YiX1oWQFdIrlSOOeXNYw3pbaPuW9Q+FyReIyvRO C0Yc1AVShCcTorJuY7MjOF+Lpascb0vjQ+PE8td+VTuwNHbsdLh4MD4cnD9S6xZh779c dbJg== X-Gm-Message-State: AGi0PuZHgP0xqlkftEqmEzTmWbKjnnFX/d91KvfpgLUsjtv9K8xv74+S QYcdZgAq14Zs06WBjmR8rsH/s331lI3yLENE/uZyqFSn X-Received: by 2002:a9d:644:: with SMTP id 62mr10091278otn.177.1587422335105; Mon, 20 Apr 2020 15:38:55 -0700 (PDT) MIME-Version: 1.0 References: <20200419211058.31987-1-pali@kernel.org> In-Reply-To: <20200419211058.31987-1-pali@kernel.org> From: Luiz Augusto von Dentz Date: Mon, 20 Apr 2020 15:38:43 -0700 Message-ID: Subject: Re: [PATCH] profile: Fix reporting error message when connection failed To: =?UTF-8?Q?Pali_Roh=C3=A1r?= Cc: "linux-bluetooth@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Pali, On Sun, Apr 19, 2020 at 2:14 PM Pali Roh=C3=A1r wrote: > > Some bluetooth headsets do not support connecting more then one bluetooth > profile (e.g. in parallel A2DP and HSP, or HSP and HFP) and issuing > connect() syscall for second profile returns just ECONNREFUSED. > > Prior this patch bluetooth daemon for such situation reported following > message to log: > > Unable to get connect data for Headset Voice gateway: getpeername: Tran= sport endpoint is not connected (107) > > Message is incorrect as connect() syscall failed, not getpeername(). This > patch fixes this problem and logs correct error message: > > Headset Voice gateway failed connect to XX:XX:XX:XX:XX:XX: Connection r= efused (111) > > Main problem was in ext_connect() function which called bt_io_get() for > retrieving remote address (BT_IO_OPT_DEST) and if it failed then original > error from connect() syscall was masked. Because it is not possible to > retrieve BT_IO_OPT_DEST for unconnected socket, original destination > address for error message is propagated via connect_add() function in bti= o. > > -- > > Having correct error message in logs is important. Due to this mangled > error message I was not able to easily debug why particular bluetooth > headset sometimes connection with nonsense error that Transport endpoint > was not connected. Looks good, but lets have the btio changes as a separate patch. > --- > btio/btio.c | 19 ++++++++++++++----- > src/profile.c | 5 +++-- > 2 files changed, 17 insertions(+), 7 deletions(-) > > diff --git a/btio/btio.c b/btio/btio.c > index e7b4db16b..3ea73faea 100644 > --- a/btio/btio.c > +++ b/btio/btio.c > @@ -85,6 +85,7 @@ struct connect { > BtIOConnect connect; > gpointer user_data; > GDestroyNotify destroy; > + bdaddr_t dst; > }; > > struct accept { > @@ -214,6 +215,7 @@ static gboolean connect_cb(GIOChannel *io, GIOConditi= on cond, > GError *gerr =3D NULL; > int err, sk_err, sock; > socklen_t len =3D sizeof(sk_err); > + char addr[18]; > > /* If the user aborted this connect attempt */ > if ((cond & G_IO_NVAL) || check_nval(io)) > @@ -226,8 +228,11 @@ static gboolean connect_cb(GIOChannel *io, GIOCondit= ion cond, > else > err =3D -sk_err; > > - if (err < 0) > - ERROR_FAILED(&gerr, "connect error", -err); > + if (err < 0) { > + ba2str(&conn->dst, addr); > + g_set_error(&gerr, BT_IO_ERROR, err, > + "connect to %s: %s (%d)", addr, strerror(-err), -= err); > + } > > conn->connect(io, gerr, conn->user_data); > > @@ -286,7 +291,7 @@ static void server_add(GIOChannel *io, BtIOConnect co= nnect, > (GDestroyNotify) server_remove); > } > > -static void connect_add(GIOChannel *io, BtIOConnect connect, > +static void connect_add(GIOChannel *io, BtIOConnect connect, bdaddr_t ds= t, > gpointer user_data, GDestroyNotify destro= y) > { > struct connect *conn; > @@ -296,6 +301,7 @@ static void connect_add(GIOChannel *io, BtIOConnect c= onnect, > conn->connect =3D connect; > conn->user_data =3D user_data; > conn->destroy =3D destroy; > + conn->dst =3D dst; > > cond =3D G_IO_OUT | G_IO_ERR | G_IO_HUP | G_IO_NVAL; > g_io_add_watch_full(io, G_PRIORITY_DEFAULT, cond, connect_cb, con= n, > @@ -1671,6 +1677,7 @@ GIOChannel *bt_io_connect(BtIOConnect connect, gpoi= nter user_data, > struct set_opts opts; > int err, sock; > gboolean ret; > + char addr[18]; > > va_start(args, opt1); > ret =3D parse_set_opts(&opts, gerr, opt1, args); > @@ -1710,12 +1717,14 @@ GIOChannel *bt_io_connect(BtIOConnect connect, gp= ointer user_data, > } > > if (err < 0) { > - ERROR_FAILED(gerr, "connect", -err); > + ba2str(&opts.dst, addr); > + g_set_error(gerr, BT_IO_ERROR, err, > + "connect to %s: %s (%d)", addr, strerror(= -err), -err); > g_io_channel_unref(io); > return NULL; > } > > - connect_add(io, connect, user_data, destroy); > + connect_add(io, connect, opts.dst, user_data, destroy); > > return io; > } > diff --git a/src/profile.c b/src/profile.c > index c2992e795..6961a107b 100644 > --- a/src/profile.c > +++ b/src/profile.c > @@ -1085,12 +1085,13 @@ static void ext_connect(GIOChannel *io, GError *e= rr, gpointer user_data) > if (!bt_io_get(io, &io_err, > BT_IO_OPT_DEST, addr, > BT_IO_OPT_INVALID)) { > - error("Unable to get connect data for %s: %s", ext->name, > - io_err->message); > if (err) { > + error("%s failed %s", ext->name, err->message); > g_error_free(io_err); > io_err =3D NULL; > } else { > + error("Unable to get connect data for %s: %s", > + ext->name, io_err->message); > err =3D io_err; > } > goto drop; > -- > 2.20.1 > --=20 Luiz Augusto von Dentz