Re: Invalid file descriptor gatttool of bluez 5.32

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Luiz et al.,

thanks for your answer and sorry for digging that thread up again. At least for the reference:

The invalid file descriptor warning stems from the g_io_channel_shutdown call in attrib/interactive.c:disconnect_io. Afaict the g_io_channel_shutdown call is redundant and thus causes the glib warning. When establishing the connection gatttool uses approximately the following call sequence.

attrib/utils.c:gatt_connect
 > btio/btio.c:bt_io_connect
    > btio/btio.c:create_io
       > **socket**
    > btio/btio.c:l2cap_connect
       > **connect**

In btio/btio.c:create_io the socket is created, a corresponding glib IO channel is created in a call to g_io_channel_unix_new and the IO channel is instructed to close the socket as soon as the last IO channel reference is dropped in a call to g_io_channel_set_close_on_unref.

When disconnecting in gatttool, the last reference to the glib IO channel seems to be dropped somewhere at the end of the following call sequence (after the last reference to the ATT object is dropped in bt_att_unref):

attrib/interactive.c:disconnect_io
 > attrib/gattrib.c:g_attrib_unref
    > src/shared/att.c:bt_att_unref
       > src/shared/att.c:bt_att_free
          > ...

In a nutshell: Afaict the g_io_channel_unref call in disconnect_io is redundant since the last IO channel reference is dropped in g_attrib_unref before this call. Since the IO channel is instructed to close the socket when the last reference is dropped, the call to g_io_channel_shutdown is also redundant (see attached patch). Applying the patch will indeed get rid of the glib warning. Can somebody second that this the correct way of fixing the cleanup sequence?

Regards,
Tobias

On 27/07/15 10:27, Luiz Augusto von Dentz wrote:
Hi Tobias,

On Mon, Jul 27, 2015 at 10:14 AM, Tobias Preclik
<linux-bluetooth@xxxxxxxxxxxxxxxxx> wrote:
Hello,

it seems the cleanup process when disconnecting from a bluetooth LE device
changed in bluez 5.32 but gatttool (attrib/interactive.c:disconnect_io)
wasn't updated.

$ ./gatttool -I
[                 ][LE]> connect FF:A7:8C:98:46:B6 random
Attempting to connect to FF:A7:8C:98:46:B6
Connection successful
[FF:A7:8C:98:46:B6][LE]> disconnect

(gatttool:20949): GLib-WARNING **: Invalid file descriptor.

[FF:A7:8C:98:46:B6][LE]> exit

What's the right way to do it in gatttool/bluez 5.32?

There are new tools to use with GATT, bluetoothctl/bluetoothd is the
preferred since with that you have GAP, etc, but if want to use a
stand alone tool then I suggest you use btgatt-client.


diff -crB bluez-5.40-orig/attrib/interactive.c bluez-5.40/attrib/interactive.c
*** bluez-5.40-orig/attrib/interactive.c	2016-07-07 15:20:13.955103280 +0200
--- bluez-5.40/attrib/interactive.c	2016-07-07 15:20:23.170926414 +0200
***************
*** 191,199 ****
  	g_attrib_unref(attrib);
  	attrib = NULL;
  	opt_mtu = 0;
- 
- 	g_io_channel_shutdown(iochannel, FALSE, NULL);
- 	g_io_channel_unref(iochannel);
  	iochannel = NULL;
  
  	set_state(STATE_DISCONNECTED);
--- 191,196 ----

[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux