summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlisses Furquim <ulissesf@gmail.com>2006-09-05 20:59:27 +0000
committerUlisses Furquim <ulissesf@gmail.com>2006-09-05 20:59:27 +0000
commitfdba3b26687425c6523f728f7e79d5f7a76af367 (patch)
tree3a083bd97026fbd27650caaf47bf83ac9bec1f10
parentc98c6d74795ed1e757da1ee2afb48d3fb09d7f91 (diff)
Store errno so it does not get changed before we use it
-rw-r--r--hcid/dbus-adapter.c39
-rw-r--r--hcid/dbus-manager.c3
-rw-r--r--hcid/device.c12
3 files changed, 36 insertions, 18 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c
index a7f1ee7c..0011ee8c 100644
--- a/hcid/dbus-adapter.c
+++ b/hcid/dbus-adapter.c
@@ -418,11 +418,12 @@ static DBusHandlerResult handle_dev_set_mode_req(DBusConnection *conn, DBusMessa
goto done; /* on success */
if (errno != EALREADY) {
+ int err = errno;
error("Can't init device hci%d: %s (%d)\n",
dbus_data->dev_id, strerror(errno), errno);
hci_close_dev(dd);
- return error_failed(conn, msg, errno);
+ return error_failed(conn, msg, err);
}
}
@@ -440,10 +441,11 @@ static DBusHandlerResult handle_dev_set_mode_req(DBusConnection *conn, DBusMessa
rq.rlen = sizeof(status);
if (hci_send_req(dd, &rq, 100) < 0) {
+ int err = errno;
error("Sending write scan enable command failed: %s (%d)",
strerror(errno), errno);
hci_close_dev(dd);
- return error_failed(conn, msg, errno);
+ return error_failed(conn, msg, err);
}
if (status) {
@@ -689,10 +691,11 @@ static DBusHandlerResult handle_dev_list_minor_classes_req(DBusConnection *conn,
return error_no_such_adapter(conn, msg);
if (hci_read_class_of_dev(dd, cls, 1000) < 0) {
+ int err = errno;
error("Can't read class of device on hci%d: %s(%d)",
dbus_data->dev_id, strerror(errno), errno);
hci_close_dev(dd);
- return error_failed(conn, msg, errno);
+ return error_failed(conn, msg, err);
}
hci_close_dev(dd);
@@ -747,10 +750,11 @@ static DBusHandlerResult handle_dev_get_minor_class_req(DBusConnection *conn, DB
return error_no_such_adapter(conn, msg);
if (hci_read_class_of_dev(dd, cls, 1000) < 0) {
+ int err = errno;
error("Can't read class of device on hci%d: %s(%d)",
dbus_data->dev_id, strerror(errno), errno);
hci_close_dev(dd);
- return error_failed(conn, msg, -errno);
+ return error_failed(conn, msg, err);
}
hci_close_dev(dd);
@@ -825,10 +829,11 @@ static DBusHandlerResult handle_dev_set_minor_class_req(DBusConnection *conn, DB
return error_no_such_adapter(conn, msg);
if (hci_read_class_of_dev(dd, cls, 1000) < 0) {
+ int err = errno;
error("Can't read class of device on hci%d: %s(%d)",
dbus_data->dev_id, strerror(errno), errno);
hci_close_dev(dd);
- return error_failed(conn, msg, errno);
+ return error_failed(conn, msg, err);
}
dev_class |= (cls[2] << 16) | (cls[1] << 8);
@@ -842,10 +847,11 @@ static DBusHandlerResult handle_dev_set_minor_class_req(DBusConnection *conn, DB
write_local_class(&bdaddr, cls);
if (hci_write_class_of_dev(dd, dev_class, 2000) < 0) {
+ int err = errno;
error("Can't write class of device on hci%d: %s(%d)",
dbus_data->dev_id, strerror(errno), errno);
hci_close_dev(dd);
- return error_failed(conn, msg, errno);
+ return error_failed(conn, msg, err);
}
signal = dev_signal_factory(dbus_data->dev_id, "MinorClassChanged",
@@ -885,10 +891,11 @@ static DBusHandlerResult handle_dev_get_service_classes_req(DBusConnection *conn
return error_no_such_adapter(conn, msg);
if (hci_read_class_of_dev(dd, cls, 1000) < 0) {
+ int err = errno;
error("Can't read class of device on hci%d: %s(%d)",
dbus_data->dev_id, strerror(errno), errno);
hci_close_dev(dd);
- return error_failed(conn, msg, errno);
+ return error_failed(conn, msg, err);
}
reply = dbus_message_new_method_return(msg);
@@ -1667,9 +1674,10 @@ static DBusHandlerResult handle_dev_disconnect_remote_device_req(DBusConnection
/* Send the HCI disconnect command */
if (hci_disconnect(dd, dev->handle, HCI_OE_USER_ENDED_CONNECTION, 100) < 0) {
+ int err = errno;
error("Disconnect failed");
hci_close_dev(dd);
- return error_failed(conn, msg, errno);
+ return error_failed(conn, msg, err);
}
hci_close_dev(dd);
@@ -1773,10 +1781,11 @@ static DBusHandlerResult handle_dev_create_bonding_req(DBusConnection *conn, DBu
}
if (hci_send_req(dd, &rq, 100) < 0) {
+ int err = errno;
error("Unable to send the HCI request: %s (%d)",
strerror(errno), errno);
hci_close_dev(dd);
- return error_failed(conn, msg, errno);
+ return error_failed(conn, msg, err);
}
if (rp.status) {
@@ -1866,10 +1875,11 @@ static DBusHandlerResult handle_dev_cancel_bonding_req(DBusConnection *conn, DBu
rq.clen = CREATE_CONN_CANCEL_CP_SIZE;
if (hci_send_req(dd, &rq, 100) < 0) {
+ int err = errno;
error("Cancel bonding - unable to send the HCI request: %s (%d)",
strerror(errno), errno);
hci_close_dev(dd);
- return error_failed(conn, msg, errno);
+ return error_failed(conn, msg, err);
}
if (rp.status) {
@@ -1974,8 +1984,9 @@ static DBusHandlerResult handle_dev_remove_bonding_req(DBusConnection *conn, DBu
/* Delete the link key from storage */
if (textfile_del(filename, addr_ptr) < 0) {
+ int err = errno;
hci_close_dev(dd);
- return error_failed(conn, msg, errno);
+ return error_failed(conn, msg, err);
}
str2ba(addr_ptr, &bdaddr);
@@ -1989,9 +2000,10 @@ static DBusHandlerResult handle_dev_remove_bonding_req(DBusConnection *conn, DBu
struct active_conn_info *con = l->data;
/* Send the HCI disconnect command */
if (hci_disconnect(dd, htobs(con->handle), HCI_OE_USER_ENDED_CONNECTION, 1000) < 0) {
+ int err = errno;
error("Disconnect failed");
hci_close_dev(dd);
- return error_failed(conn, msg, errno);
+ return error_failed(conn, msg, err);
}
}
@@ -2213,10 +2225,11 @@ static DBusHandlerResult handle_dev_discover_devices_req(DBusConnection *conn, D
rq.event = EVT_CMD_STATUS;
if (hci_send_req(dd, &rq, 100) < 0) {
+ int err = errno;
error("Unable to start inquiry: %s (%d)",
strerror(errno), errno);
hci_close_dev(dd);
- return error_failed(conn, msg, errno);
+ return error_failed(conn, msg, err);
}
if (rp.status) {
diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c
index b4805632..dcad1d3a 100644
--- a/hcid/dbus-manager.c
+++ b/hcid/dbus-manager.c
@@ -146,9 +146,10 @@ static DBusHandlerResult list_adapters(DBusConnection *conn,
dr = dl->dev_req;
if (ioctl(sk, HCIGETDEVLIST, dl) < 0) {
+ int err = errno;
close(sk);
free(dl);
- return error_failed(conn, msg, errno);
+ return error_failed(conn, msg, err);
}
dr = dl->dev_req;
diff --git a/hcid/device.c b/hcid/device.c
index 883d6feb..2831fcc7 100644
--- a/hcid/device.c
+++ b/hcid/device.c
@@ -111,10 +111,11 @@ static int device_read_bdaddr(uint16_t dev_id, bdaddr_t *bdaddr)
}
if (hci_read_bd_addr(dd, bdaddr, 2000) < 0) {
+ int err = errno;
error("Can't read address for hci%d: %s (%d)",
dev_id, strerror(errno), errno);
hci_close_dev(dd);
- return -errno;
+ return -err;
}
hci_close_dev(dd);
@@ -216,10 +217,11 @@ int start_device(uint16_t dev_id)
}
if (hci_read_local_version(dd, &ver, 1000) < 0) {
+ int err = errno;
error("Can't read version info for hci%d: %s (%d)",
dev_id, strerror(errno), errno);
hci_close_dev(dd);
- return -errno;
+ return -err;
}
dev->hci_rev = ver.hci_rev;
@@ -228,10 +230,11 @@ int start_device(uint16_t dev_id)
dev->manufacturer = ver.manufacturer;
if (hci_read_local_features(dd, features, 1000) < 0) {
+ int err = errno;
error("Can't read features for hci%d: %s (%d)",
dev_id, strerror(errno), errno);
hci_close_dev(dd);
- return -errno;
+ return -err;
}
memcpy(dev->features, features, 8);
@@ -241,10 +244,11 @@ int start_device(uint16_t dev_id)
goto done;
if (hci_write_inquiry_mode(dd, inqmode, 1000) < 0) {
+ int err = errno;
error("Can't write inquiry mode for hci%d: %s (%d)",
dev_id, strerror(errno), errno);
hci_close_dev(dd);
- return -errno;
+ return -err;
}
done: