Referted the 'Fireofox 1.5' fix in log.c and replaced it by letting a blocking C_WaitForSlotEvent() return CKR_FUNCTION_NOT_SUPPORTED. This isn't a solution for the multihread problems (things hang or try to log to a released context) but at least it solves the Ff 1.5 problems

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2777 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
sth 2005-12-23 10:15:17 +00:00
parent e56c7a9110
commit 551bcc89fa
2 changed files with 17 additions and 14 deletions

View File

@ -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)

View File

@ -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;