From: Luiz Fernando Capitulino <lcapitulino@conectiva.com.br>
To: bluez-devel@lists.sourceforge.net, marcel@holtmann.org
Subject: [PATCH] - Some errno usage fixes (bluez-libs).
Date: Tue, 21 Jun 2005 12:17:34 -0300 [thread overview]
Message-ID: <42B82F8E.1050506@conectiva.com.br> (raw)
[-- 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.
next reply other threads:[~2005-06-21 15:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-21 15:17 Luiz Fernando Capitulino [this message]
2005-06-21 16:50 ` [Bluez-devel] Re: [PATCH] - Some errno usage fixes (bluez-libs) Marcel Holtmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=42B82F8E.1050506@conectiva.com.br \
--to=lcapitulino@conectiva.com.br \
--cc=bluez-devel@lists.sourceforge.net \
--cc=marcel@holtmann.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.