summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2009-06-30 21:26:33 +0300
committerJohan Hedberg <johan.hedberg@nokia.com>2009-06-30 21:26:33 +0300
commit18e8b33f0d60b9e1f4a6521720e14e9db1cda01d (patch)
treeaeba72e4954cbb6ede6e57c12c2c454377dcfaeb /plugins
parent0b0bbd589c6484ff6c06d1465e53baeca625311e (diff)
Fix error handling in hciops initialization
Diffstat (limited to 'plugins')
-rw-r--r--plugins/hciops.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/plugins/hciops.c b/plugins/hciops.c
index dae79b32..f1d58980 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -53,7 +53,7 @@
#include "manager.h"
#include "storage.h"
-static int child_pipe[2];
+static int child_pipe[2] = { -1, -1 };
static gboolean child_exit(GIOChannel *io, GIOCondition cond, void *user_data)
{
@@ -277,22 +277,24 @@ static int init_known_adapters(int ctl)
{
struct hci_dev_list_req *dl;
struct hci_dev_req *dr;
- int i;
+ int i, err;
dl = g_try_malloc0(HCI_MAX_DEV * sizeof(struct hci_dev_req) + sizeof(uint16_t));
if (!dl) {
- info("Can't allocate devlist buffer: %s (%d)",
+ err = -errno;
+ error("Can't allocate devlist buffer: %s (%d)",
strerror(errno), errno);
- return errno;
+ return err;
}
dl->dev_num = HCI_MAX_DEV;
dr = dl->dev_req;
if (ioctl(ctl, HCIGETDEVLIST, (void *) dl) < 0) {
- info("Can't get device list: %s (%d)",
+ err = -errno;
+ error("Can't get device list: %s (%d)",
strerror(errno), errno);
- return errno;
+ return err;
}
for (i = 0; i < dl->dev_num; i++, dr++) {
@@ -359,11 +361,15 @@ static int hciops_setup(void)
struct sockaddr_hci addr;
struct hci_filter flt;
GIOChannel *ctl_io, *child_io;
- int sock;
+ int sock, err;
+
+ if (child_pipe[0] != -1)
+ return -EALREADY;
if (pipe(child_pipe) < 0) {
+ err = -errno;
error("pipe(): %s (%d)", strerror(errno), errno);
- return errno;
+ return err;
}
child_io = g_io_channel_unix_new(child_pipe[0]);
@@ -376,9 +382,10 @@ static int hciops_setup(void)
/* Create and bind HCI socket */
sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (sock < 0) {
+ err = -errno;
error("Can't open HCI socket: %s (%d)", strerror(errno),
errno);
- return errno;
+ return err;
}
/* Set filter */
@@ -387,8 +394,9 @@ static int hciops_setup(void)
hci_filter_set_event(EVT_STACK_INTERNAL, &flt);
if (setsockopt(sock, SOL_HCI, HCI_FILTER, &flt,
sizeof(flt)) < 0) {
+ err = -errno;
error("Can't set filter: %s (%d)", strerror(errno), errno);
- return errno;
+ return err;
}
memset(&addr, 0, sizeof(addr));
@@ -396,9 +404,10 @@ static int hciops_setup(void)
addr.hci_dev = HCI_DEV_NONE;
if (bind(sock, (struct sockaddr *) &addr,
sizeof(addr)) < 0) {
+ err = -errno;
error("Can't bind HCI socket: %s (%d)",
strerror(errno), errno);
- return errno;
+ return err;
}
ctl_io = g_io_channel_unix_new(sock);