diff --git a/src/libopensc/log.c b/src/libopensc/log.c index 08e025c8..0e4b057b 100644 --- a/src/libopensc/log.c +++ b/src/libopensc/log.c @@ -70,20 +70,14 @@ void sc_do_log_va(sc_context_t *ctx, int type, const char *file, int line, const int (*display_fn)(sc_context_t *, const char *); char buf[1536], *p; const char *tag = ""; - int r, suppress_errors; + int r; size_t left; - /* In case of multiple threads, this function could be called in one thread - * while another thread already release the context and set it to NULL. - * This is the case with our pkcs11 lib in e.g. Firefox 1.5. */ - if (ctx == NULL) - suppress_errors = 0; - else - suppress_errors = ctx->suppress_errors; + assert(ctx != NULL); switch (type) { case SC_LOG_TYPE_ERROR: - if (!suppress_errors) { + if (!ctx->suppress_errors) { display_fn = &sc_ui_display_error; tag = "error:"; break; @@ -94,7 +88,7 @@ void sc_do_log_va(sc_context_t *ctx, int type, const char *file, int line, const type = SC_LOG_TYPE_DEBUG; case SC_LOG_TYPE_DEBUG: - if (ctx != NULL && ctx->debug == 0) + if (ctx->debug == 0) return; display_fn = &sc_ui_display_debug; break; @@ -119,10 +113,7 @@ void sc_do_log_va(sc_context_t *ctx, int type, const char *file, int line, const p += r; left -= r; - if (ctx != NULL) - display_fn(ctx, buf); - else - fprintf(stderr, buf); + display_fn(ctx, buf); } void sc_hex_dump(sc_context_t *ctx, const u8 * in, size_t count, char *buf, size_t len) diff --git a/src/pkcs11/pkcs11-global.c b/src/pkcs11/pkcs11-global.c index 5c663bbe..341a3233 100644 --- a/src/pkcs11/pkcs11-global.c +++ b/src/pkcs11/pkcs11-global.c @@ -346,6 +346,18 @@ CK_RV C_WaitForSlotEvent(CK_FLAGS flags, /* blocking/nonblocking flag */ unsigned int mask, events; CK_RV rv; + /* Firefox 1.5 calls this function (blocking) from a seperate thread, + * which gives 2 problems: + * - on Windows/Mac: this waiting thread will log to a NULL context + * after the 'main' thread does a C_Finalize() and sets the ctx to NULL. + * - on Linux, things just hang (at least on Debian 'sid') + * So we just return CKR_FUNCTION_NOT_SUPPORTED on a blocking call, + * in which case Ff just seems to default to polling in the main thread + * as the Mozilla family of browsers did before. + */ + if (!(flags & CKF_DONT_BLOCK)) + return CKR_FUNCTION_NOT_SUPPORTED; + rv = sc_pkcs11_lock(); if (rv != CKR_OK) return rv;