diff options
author | Hans de Goede <hdegoede@redhat.com> | 2013-10-15 16:03:05 +0200 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2013-11-20 13:21:49 +0100 |
commit | 850dc391cfc6e3f7e8cf917f8baf646ae7ca83a1 (patch) | |
tree | ae0f3eb6111bdcf567b3591560e89a4a802ad813 | |
parent | 15ee9598454f0c3b6221f45d36c38fb474af74df (diff) | |
download | libusb-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>
-rw-r--r-- | libusb/core.c | 21 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
2 files changed, 15 insertions, 8 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 diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 7deeae0..e9bdb4e 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10849 +#define LIBUSB_NANO 10850 |