# how to cleanly shutdown an application using HCI\_CHANNEL\_USER

- From: Peter A. Bigot \<hidden\>
- Date: 2021-08-17 22:07:22 
- List: linux-bluetooth
- Page: https://ratatoskr.run/linux-bluetooth/2021/08/9681127
- Thread: https://ratatoskr.run/linux-bluetooth/2021/08/9681127/t.md

```text
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.

Thanks!

Peter
```
