initialize notifications in PKCS#11 and tools

... and don't panic when they are not initialized
This commit is contained in:
Frank Morgner 2017-11-08 12:23:05 +01:00
parent 3f0d5ce336
commit 654ca69c47
3 changed files with 31 additions and 18 deletions

View File

@ -35,6 +35,7 @@
#endif /* PKCS11_THREAD_LOCKING */ #endif /* PKCS11_THREAD_LOCKING */
#include "sc-pkcs11.h" #include "sc-pkcs11.h"
#include "ui/notify.h"
#ifndef MODULE_APP_NAME #ifndef MODULE_APP_NAME
#define MODULE_APP_NAME "opensc-pkcs11" #define MODULE_APP_NAME "opensc-pkcs11"
@ -237,6 +238,8 @@ CK_RV C_Initialize(CK_VOID_PTR pInitArgs)
return CKR_CRYPTOKI_ALREADY_INITIALIZED; return CKR_CRYPTOKI_ALREADY_INITIALIZED;
} }
sc_notify_init();
rv = sc_pkcs11_init_lock((CK_C_INITIALIZE_ARGS_PTR) pInitArgs); rv = sc_pkcs11_init_lock((CK_C_INITIALIZE_ARGS_PTR) pInitArgs);
if (rv != CKR_OK) if (rv != CKR_OK)
goto out; goto out;
@ -300,6 +303,8 @@ CK_RV C_Finalize(CK_VOID_PTR pReserved)
if (pReserved != NULL_PTR) if (pReserved != NULL_PTR)
return CKR_ARGUMENTS_BAD; return CKR_ARGUMENTS_BAD;
sc_notify_close();
if (context == NULL) if (context == NULL)
return CKR_CRYPTOKI_NOT_INITIALIZED; return CKR_CRYPTOKI_NOT_INITIALIZED;

View File

@ -30,6 +30,7 @@
#endif #endif
#include <ctype.h> #include <ctype.h>
#include "util.h" #include "util.h"
#include "ui/notify.h"
int int
is_string_valid_atr(const char *atr_str) is_string_valid_atr(const char *atr_str)
@ -54,6 +55,8 @@ util_connect_card_ex(sc_context_t *ctx, sc_card_t **cardp,
struct sc_card *card = NULL; struct sc_card *card = NULL;
int r; int r;
sc_notify_init();
if (do_wait) { if (do_wait) {
unsigned int event; unsigned int event;
@ -354,6 +357,9 @@ util_fatal(const char *fmt, ...)
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);
fprintf(stderr, "\nAborting.\n"); fprintf(stderr, "\nAborting.\n");
va_end(ap); va_end(ap);
sc_notify_close();
exit(1); exit(1);
} }

View File

@ -398,6 +398,7 @@ static void notify_gio(struct sc_context *ctx,
const char *title, const char *text, const char *icon, const char *title, const char *text, const char *icon,
const char *group) const char *group)
{ {
if (application) {
GIcon *gicon = NULL; GIcon *gicon = NULL;
GNotification *notification = g_notification_new (title); GNotification *notification = g_notification_new (title);
if (!notification) { if (!notification) {
@ -421,6 +422,7 @@ static void notify_gio(struct sc_context *ctx,
} }
g_object_unref(notification); g_object_unref(notification);
} }
}
#else #else