aboutsummaryrefslogtreecommitdiff
path: root/lib/libusb
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2019-10-02 15:19:39 +0000
committerKyle Evans <kevans@FreeBSD.org>2019-10-02 15:19:39 +0000
commit8495fa081bb0c8a4be80488972fca09c9400f53c (patch)
tree991563b9adca0a6123583408e9910c62a93a4660 /lib/libusb
parent22c2c971a614a72875787e0fd0001906451ee245 (diff)
Notes
Diffstat (limited to 'lib/libusb')
-rw-r--r--lib/libusb/libusb10.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c
index 43199c089e7c..6f61353a76b3 100644
--- a/lib/libusb/libusb10.c
+++ b/lib/libusb/libusb10.c
@@ -91,7 +91,8 @@ void
libusb_set_debug(libusb_context *ctx, int level)
{
ctx = GET_CONTEXT(ctx);
- if (ctx)
+ /* debug_fixed is set when the environment overrides libusb_set_debug */
+ if (ctx && ctx->debug_fixed == 0)
ctx->debug = level;
}
@@ -132,7 +133,7 @@ libusb_init(libusb_context **context)
{
struct libusb_context *ctx;
pthread_condattr_t attr;
- char *debug;
+ char *debug, *ep;
int ret;
ctx = malloc(sizeof(*ctx));
@@ -143,9 +144,23 @@ libusb_init(libusb_context **context)
debug = getenv("LIBUSB_DEBUG");
if (debug != NULL) {
- ctx->debug = atoi(debug);
- if (ctx->debug != 0)
+ /*
+ * If LIBUSB_DEBUG is set, we'll honor that and use it to
+ * override libusb_set_debug calls.
+ */
+ errno = 0;
+ ctx->debug = strtol(debug, &ep, 10);
+ if (errno == 0 && *ep == '\0') {
ctx->debug_fixed = 1;
+ } else {
+ /*
+ * LIBUSB_DEBUG conversion failed for some reason, but
+ * we don't care about the specifics all that much. We
+ * can't use it either way. Force it to the default,
+ * 0, in case we had a partial number.
+ */
+ ctx->debug = 0;
+ }
}
TAILQ_INIT(&ctx->pollfds);
TAILQ_INIT(&ctx->tr_done);