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

View File

@ -30,6 +30,7 @@
#endif
#include <ctype.h>
#include "util.h"
#include "ui/notify.h"
int
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;
int r;
sc_notify_init();
if (do_wait) {
unsigned int event;
@ -354,6 +357,9 @@ util_fatal(const char *fmt, ...)
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\nAborting.\n");
va_end(ap);
sc_notify_close();
exit(1);
}

View File

@ -398,28 +398,30 @@ static void notify_gio(struct sc_context *ctx,
const char *title, const char *text, const char *icon,
const char *group)
{
GIcon *gicon = NULL;
GNotification *notification = g_notification_new (title);
if (!notification) {
return;
}
if (text) {
g_notification_set_body (notification, text);
}
if (icon) {
gicon = g_themed_icon_new (icon);
if (gicon) {
g_notification_set_icon (notification, gicon);
if (application) {
GIcon *gicon = NULL;
GNotification *notification = g_notification_new (title);
if (!notification) {
return;
}
}
g_application_send_notification(application, group, notification);
if (text) {
g_notification_set_body (notification, text);
}
if (icon) {
gicon = g_themed_icon_new (icon);
if (gicon) {
g_notification_set_icon (notification, gicon);
}
}
if (gicon) {
g_object_unref(gicon);
g_application_send_notification(application, group, notification);
if (gicon) {
g_object_unref(gicon);
}
g_object_unref(notification);
}
g_object_unref(notification);
}
#else