core: Allow setting global log callback after first libusb_init()

When setting LIBUSB_OPTION_LOG_CB before the first libusb_init(),
the global callback is set.

However, after the first libusb_init() there is a default context, and
setting LIBUSB_OPTION_LOG_CB would only set this default context, and
not the global callback. There would be no way to set the global
callback through libusb_set_option().

Change this so that the global log callback is set in addition to the
default context (when libusb_set_option is called with NULL context).

Closes #1397
This commit is contained in:
Lars Kanis
2023-12-21 12:37:51 +01:00
committed by Tormod Volden
parent d09d341f41
commit a5483bc0f7
2 changed files with 3 additions and 5 deletions

View File

@@ -2327,16 +2327,14 @@ int API_EXPORTEDV libusb_set_option(libusb_context *ctx,
default_context_options[option].arg.ival = arg;
} else if (LIBUSB_OPTION_LOG_CB == option) {
default_context_options[option].arg.log_cbval = log_cb;
libusb_set_log_cb_internal(NULL, log_cb, LIBUSB_LOG_CB_GLOBAL);
}
usbi_mutex_static_unlock(&default_context_lock);
}
ctx = usbi_get_context(ctx);
if (NULL == ctx) {
if (LIBUSB_OPTION_LOG_CB == option)
libusb_set_log_cb_internal(NULL, log_cb, LIBUSB_LOG_CB_GLOBAL);
if (NULL == ctx)
break;
}
switch (option) {
case LIBUSB_OPTION_LOG_LEVEL:

View File

@@ -1 +1 @@
#define LIBUSB_NANO 11875
#define LIBUSB_NANO 11876