* [PATCH] tools: Fix glib assert in mgmt-tester if hci_vhci module is not loaded
@ 2013-01-21 20:25 Szymon Janc
2013-01-25 7:50 ` Johan Hedberg
0 siblings, 1 reply; 2+ messages in thread
From: Szymon Janc @ 2013-01-21 20:25 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Print descriptive warning on HCI emulation setup failure and fail test
gracefully. This is better comparing to glib assertion when not fully
initialized HCI emulation is being unreferenced.
---
src/shared/hciemu.c | 31 ++++++++++++++++++++++---------
tools/mgmt-tester.c | 4 ++++
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/src/shared/hciemu.c b/src/shared/hciemu.c
index d523743..a15102d 100644
--- a/src/shared/hciemu.c
+++ b/src/shared/hciemu.c
@@ -188,7 +188,7 @@ static guint create_source_btdev(int fd, struct btdev *btdev)
return source;
}
-static void create_vhci(struct hciemu *hciemu)
+static bool create_vhci(struct hciemu *hciemu)
{
struct btdev *btdev;
uint8_t bdaddr[6];
@@ -197,7 +197,7 @@ static void create_vhci(struct hciemu *hciemu)
btdev = btdev_create(BTDEV_TYPE_BREDR, 0x00);
if (!btdev)
- return;
+ return false;
str = hciemu_get_address(hciemu);
@@ -210,15 +210,17 @@ static void create_vhci(struct hciemu *hciemu)
fd = open("/dev/vhci", O_RDWR | O_NONBLOCK | O_CLOEXEC);
if (fd < 0) {
btdev_destroy(btdev);
- return;
+ return false;
}
hciemu->master_dev = btdev;
hciemu->master_source = create_source_btdev(fd, btdev);
+
+ return true;
}
-static void create_stack(struct hciemu *hciemu)
+static bool create_stack(struct hciemu *hciemu)
{
struct btdev *btdev;
struct bthost *bthost;
@@ -226,12 +228,12 @@ static void create_stack(struct hciemu *hciemu)
btdev = btdev_create(BTDEV_TYPE_BREDR, 0x00);
if (!btdev)
- return;
+ return false;
bthost = bthost_create();
if (!bthost) {
btdev_destroy(btdev);
- return;
+ return false;
}
btdev_set_command_handler(btdev, client_command_callback, hciemu);
@@ -240,7 +242,7 @@ static void create_stack(struct hciemu *hciemu)
0, sv) < 0) {
bthost_destroy(bthost);
btdev_destroy(btdev);
- return;
+ return false;
}
hciemu->client_dev = btdev;
@@ -248,6 +250,8 @@ static void create_stack(struct hciemu *hciemu)
hciemu->client_source = create_source_btdev(sv[0], btdev);
hciemu->host_source = create_source_bthost(sv[1], bthost);
+
+ return true;
}
static gboolean start_stack(gpointer user_data)
@@ -267,8 +271,17 @@ struct hciemu *hciemu_new(void)
if (!hciemu)
return NULL;
- create_vhci(hciemu);
- create_stack(hciemu);
+ if (!create_vhci(hciemu)) {
+ g_free(hciemu);
+ return NULL;
+ }
+
+ if (!create_stack(hciemu)) {
+ g_source_remove(hciemu->master_source);
+ btdev_destroy(hciemu->master_dev);
+ g_free(hciemu);
+ return NULL;
+ }
g_idle_add(start_stack, hciemu);
diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index bf61f9d..63e7714 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -217,6 +217,10 @@ static void read_index_list_callback(uint8_t status, uint16_t length,
index_removed_callback, NULL, NULL);
data->hciemu = hciemu_new();
+ if (!data->hciemu) {
+ tester_warn("Failed to setup HCI emulation");
+ tester_pre_setup_failed();
+ }
}
static void test_pre_setup(const void *test_data)
--
1.8.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tools: Fix glib assert in mgmt-tester if hci_vhci module is not loaded
2013-01-21 20:25 [PATCH] tools: Fix glib assert in mgmt-tester if hci_vhci module is not loaded Szymon Janc
@ 2013-01-25 7:50 ` Johan Hedberg
0 siblings, 0 replies; 2+ messages in thread
From: Johan Hedberg @ 2013-01-25 7:50 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi Szymon,
On Mon, Jan 21, 2013, Szymon Janc wrote:
> Print descriptive warning on HCI emulation setup failure and fail test
> gracefully. This is better comparing to glib assertion when not fully
> initialized HCI emulation is being unreferenced.
> ---
> src/shared/hciemu.c | 31 ++++++++++++++++++++++---------
> tools/mgmt-tester.c | 4 ++++
> 2 files changed, 26 insertions(+), 9 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-01-25 7:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-21 20:25 [PATCH] tools: Fix glib assert in mgmt-tester if hci_vhci module is not loaded Szymon Janc
2013-01-25 7:50 ` Johan Hedberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).