All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcel Holtmann <marcel@holtmann.org>
To: "Peter A. Bigot" <pab@pabigot.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: how to cleanly shutdown an application using HCI_CHANNEL_USER
Date: Thu, 19 Aug 2021 17:01:42 +0200	[thread overview]
Message-ID: <A6782BCD-0C05-40AD-B567-7A1E163184E0@holtmann.org> (raw)
In-Reply-To: <e17b2044-62cb-cbf7-64b8-c647aa7f6ee7@pabigot.com>

Hi Peter,

> I'm using an AF_BLUETOOTH socket bound with HCI_CHANNEL_USER from a
> user-mode application with cap_net_admin=ep.  As expected this
> requires the device be down, and brings the device up automatically.
> 
> When I close that socket and exit the application, the device appears
> to remain up forever.  Which prevents me from re-starting the
> application.
> 
> I tried to issue HCIDEVDOWN before closing, but that produces EBADFD
> because ioctls cannot be performed with HCI_CHANNEL_RAW.
> 
> I can bring the interface down from within the application if, after
> closing the socket, I wait a second or so, then create a new bound
> HCI_CHANNEL_RAW socket and issue HCIDEVDOWN on it.
> 
> Is there some other way to cleanly shut down an application that used
> HCI_CHANNEL_USER so that the device is returned to down state on exit?
> Or is this supposed to happen automatically (I see code that suggests
> it should)?
> 
> Kernel version is 5.11.0-7620-generic (System76), and I'm using go
> 1.16, if that's relevant.

I think you found a regression. Calling close() on the HCI User Channel should bring the device back down. This used to work correctly, can you please bisect which kernel patch broke this.

Back in the days I added tools/userchan-tester, but it seems I never included enough test cases to catch this regression.

Regards

Marcel


  reply	other threads:[~2021-08-19 15:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17 22:07 how to cleanly shutdown an application using HCI_CHANNEL_USER Peter A. Bigot
2021-08-19 15:01 ` Marcel Holtmann [this message]
2021-08-19 17:51   ` Luiz Augusto von Dentz
2021-08-23 20:32   ` Tedd Ho-Jeong An

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=A6782BCD-0C05-40AD-B567-7A1E163184E0@holtmann.org \
    --to=marcel@holtmann.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=pab@pabigot.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.