* [PATCH] - Some errno usage fixes (bluez-libs).
@ 2005-06-21 15:17 Luiz Fernando Capitulino
2005-06-21 16:50 ` [Bluez-devel] " Marcel Holtmann
0 siblings, 1 reply; 2+ messages in thread
From: Luiz Fernando Capitulino @ 2005-06-21 15:17 UTC (permalink / raw)
To: bluez-devel, marcel
[-- Attachment #1: Type: text/plain, Size: 657 bytes --]
Hi there!
The bluez-libs functions hci_for_each_dev(), hci_devinfo() and
hci_inquiry() don't save the 'errno' value when an error occurs.
This causes the value of 'errno' to be overwrinting on some kind
of errors.
The attached patch fixes it. Note that was necessary to change
hci_inquiry() a bit, and I've added the missing error code to 'errno'
when a device is not found by hci_for_each_dev(), it fixes things like
that:
~/ hcitool scan
Device is not available: Success
~/
src/hci.c | 70 ++++++++++++++++++++++++++++++++++++--------------------------
1 files changed, 41 insertions(+), 29 deletions(-)
Thank you,
--
Luiz Fernando N. Capitulino
[-- Attachment #2: bluez_libs_errno_usage.patch --]
[-- Type: text/x-patch, Size: 2710 bytes --]
src/hci.c | 70 ++++++++++++++++++++++++++++++++++++--------------------------
1 files changed, 41 insertions(+), 29 deletions(-)
diff -X /home/lcapitulino/kernels/2.6/dontdiff -Nparu a/src/hci.c a~/src/hci.c
--- a/src/hci.c 2005-06-16 10:53:09.000000000 -0300
+++ a~/src/hci.c 2005-06-21 11:32:53.000000000 -0300
@@ -463,17 +463,15 @@ int hci_for_each_dev(int flag, int (*fun
struct hci_dev_list_req *dl;
struct hci_dev_req *dr;
int dev_id = -1;
- int i, sk;
+ int err, i, sk;
sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (sk < 0)
return -1;
dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
- if (!dl) {
- close(sk);
- return -1;
- }
+ if (!dl)
+ goto done;
dl->dev_num = HCI_MAX_DEV;
dr = dl->dev_req;
@@ -489,9 +487,15 @@ int hci_for_each_dev(int flag, int (*fun
}
}
+ if (dev_id < 0)
+ errno = ENODEV;
+
done:
+ err = errno;
close(sk);
- free(dl);
+ if (dl)
+ free(dl);
+ errno = err;
return dev_id;
}
@@ -545,17 +549,20 @@ int hci_devid(const char *str)
int hci_devinfo(int dev_id, struct hci_dev_info *di)
{
- int s, err;
+ int s, err, ret;
s = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (s < 0)
return s;
di->dev_id = dev_id;
- err = ioctl(s, HCIGETDEVINFO, (void *) di);
+ ret = ioctl(s, HCIGETDEVINFO, (void *) di);
+
+ err = errno;
close(s);
+ errno = err;
- return err;
+ return ret;
}
int hci_devba(int dev_id, bdaddr_t *bdaddr)
@@ -579,7 +586,8 @@ int hci_inquiry(int dev_id, int len, int
struct hci_inquiry_req *ir;
uint8_t num_rsp = nrsp;
void *buf;
- int s, err;
+ int ret = -1;
+ int size, s, err;
if (nrsp <= 0) {
num_rsp = 0;
@@ -596,10 +604,8 @@ int hci_inquiry(int dev_id, int len, int
return -1;
buf = malloc(sizeof(*ir) + (sizeof(inquiry_info) * (nrsp)));
- if (!buf) {
- close(s);
- return -1;
- }
+ if (!buf)
+ goto out;
ir = buf;
ir->dev_id = dev_id;
@@ -615,23 +621,29 @@ int hci_inquiry(int dev_id, int len, int
ir->lap[2] = 0x9e;
}
- err = ioctl(s, HCIINQUIRY, (unsigned long) buf);
- close(s);
-
- if (!err) {
- int size = sizeof(inquiry_info) * ir->num_rsp;
+ ret = ioctl(s, HCIINQUIRY, (unsigned long) buf);
+ if (ret < 0)
+ goto out;
+
+ size = sizeof(inquiry_info) * ir->num_rsp;
+
+ if (!*ii)
+ *ii = (void *) malloc(size);
+
+ if (*ii) {
+ memcpy((void *) *ii, buf + sizeof(*ir), size);
+ ret = ir->num_rsp;
+ } else
+ ret = -1;
- if (!*ii)
- *ii = (void *) malloc(size);
+out:
+ err = errno;
+ close(s);
+ if (buf)
+ free(buf);
+ errno = err;
- if (*ii) {
- memcpy((void *) *ii, buf + sizeof(*ir), size);
- err = ir->num_rsp;
- } else
- err = -1;
- }
- free(buf);
- return err;
+ return ret;
}
/* Open HCI device.
^ permalink raw reply [flat|nested] 2+ messages in thread* [Bluez-devel] Re: [PATCH] - Some errno usage fixes (bluez-libs).
2005-06-21 15:17 [PATCH] - Some errno usage fixes (bluez-libs) Luiz Fernando Capitulino
@ 2005-06-21 16:50 ` Marcel Holtmann
0 siblings, 0 replies; 2+ messages in thread
From: Marcel Holtmann @ 2005-06-21 16:50 UTC (permalink / raw)
To: Luiz Fernando Capitulino; +Cc: bluez-devel
Hi Luiz,
> The bluez-libs functions hci_for_each_dev(), hci_devinfo() and
> hci_inquiry() don't save the 'errno' value when an error occurs.
> This causes the value of 'errno' to be overwrinting on some kind
> of errors.
>
> The attached patch fixes it. Note that was necessary to change
> hci_inquiry() a bit, and I've added the missing error code to 'errno'
> when a device is not found by hci_for_each_dev(), it fixes things like
> that:
thanks for the patch. A slight modified version is in the CVS now.
Regards
Marcel
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-06-21 16:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-21 15:17 [PATCH] - Some errno usage fixes (bluez-libs) Luiz Fernando Capitulino
2005-06-21 16:50 ` [Bluez-devel] " Marcel Holtmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.