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 <hdego...@redhat.com>
---
 libusb/core.c         | 21 ++++++++++++++-------
 libusb/version_nano.h |  2 +-
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/libusb/core.c b/libusb/core.c
index b472e89..8d78243 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -2158,17 +2158,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
 
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index a833d52..a387990 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 10839
+#define LIBUSB_NANO 10840
-- 
1.8.3.1


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to