summaryrefslogtreecommitdiff
path: root/libusb/core.c
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2013-10-15 16:03:05 +0200
committerHans de Goede <hdegoede@redhat.com>2013-11-20 13:21:49 +0100
commit850dc391cfc6e3f7e8cf917f8baf646ae7ca83a1 (patch)
treeae0f3eb6111bdcf567b3591560e89a4a802ad813 /libusb/core.c
parent15ee9598454f0c3b6221f45d36c38fb474af74df (diff)
downloadlibusb-850dc391cfc6e3f7e8cf917f8baf646ae7ca83a1.tar.gz
core: Make LIBUSB_DEBUG environment variable also work from libusb_exit
libusb_exit sets usbi_default_context to NULL, modify usbi_log_v so that it still honors the LIBUSB_DEBUG environment variable in this case. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'libusb/core.c')
-rw-r--r--libusb/core.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/libusb/core.c b/libusb/core.c
index a87cf96..f48517b 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -2096,17 +2096,24 @@ void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
global_debug = 1;
UNUSED(ctx);
#else
+ int ctx_level = 0;
+
USBI_GET_CONTEXT(ctx);
- if (ctx == NULL)
- return;
- global_debug = (ctx->debug == LIBUSB_LOG_LEVEL_DEBUG);
- if (!ctx->debug)
+ if (ctx) {
+ ctx_level = ctx->debug;
+ } else {
+ char *dbg = getenv("LIBUSB_DEBUG");
+ if (dbg)
+ ctx_level = atoi(dbg);
+ }
+ global_debug = (ctx_level == LIBUSB_LOG_LEVEL_DEBUG);
+ if (!ctx_level)
return;
- if (level == LIBUSB_LOG_LEVEL_WARNING && ctx->debug < LIBUSB_LOG_LEVEL_WARNING)
+ if (level == LIBUSB_LOG_LEVEL_WARNING && ctx_level < LIBUSB_LOG_LEVEL_WARNING)
return;
- if (level == LIBUSB_LOG_LEVEL_INFO && ctx->debug < LIBUSB_LOG_LEVEL_INFO)
+ if (level == LIBUSB_LOG_LEVEL_INFO && ctx_level < LIBUSB_LOG_LEVEL_INFO)
return;
- if (level == LIBUSB_LOG_LEVEL_DEBUG && ctx->debug < LIBUSB_LOG_LEVEL_DEBUG)
+ if (level == LIBUSB_LOG_LEVEL_DEBUG && ctx_level < LIBUSB_LOG_LEVEL_DEBUG)
return;
#endif