From c46a9ea89b8b28ea182f332af1025907d2283df1 Mon Sep 17 00:00:00 2001 From: Maksim Yevmenkin Date: Wed, 18 May 2005 23:03:44 +0000 Subject: [PATCH] Fix problem with session termination. bthidd(8) maintains two L2CAP connections to Bluetooth HID device. As soon as Bluetooth HID device is powered off (or goes out of RF range) the stack will terminate both connections. File descriptors for both connections will become active on next select(2) call. Because bthidd(8) processes file descriptors in order, it will detect descriptor for one of the closed connections first and kill the session. However, there is still a second (active) descriptor that used to point to the same session. bthidd(8) used to assert() if it cant find session by file descriptor, which was wrong. While I'm here fix a couple of typos in parser.y Reported by: Eric Anderson anderson AT centtech DOT com MFC after: 3 days --- usr.sbin/bluetooth/bthidd/parser.y | 4 ++-- usr.sbin/bluetooth/bthidd/server.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/usr.sbin/bluetooth/bthidd/parser.y b/usr.sbin/bluetooth/bthidd/parser.y index 7a95d26a528d..eda82f649652 100644 --- a/usr.sbin/bluetooth/bthidd/parser.y +++ b/usr.sbin/bluetooth/bthidd/parser.y @@ -315,12 +315,12 @@ print_hid_device(hid_device_p hid_device, FILE *f) for (i = 0; i < desc->size; i ++) { if ((i % 8) == 0) - fprintf(stdout, "\n "); + fprintf(f, "\n "); fprintf(f, "0x%2.2x ", desc->data[i]); } - fprintf(stdout, + fprintf(f, "\n" \ " };\n" \ "}\n"); diff --git a/usr.sbin/bluetooth/bthidd/server.c b/usr.sbin/bluetooth/bthidd/server.c index e2f716e22170..ad2c82835f43 100644 --- a/usr.sbin/bluetooth/bthidd/server.c +++ b/usr.sbin/bluetooth/bthidd/server.c @@ -332,7 +332,8 @@ server_process(bthid_server_p srv, int fd) char data[1024]; int len; - assert(s != NULL); + if (s == NULL) + return (0); /* can happen on device disconnect */ do { len = read(fd, data, sizeof(data));