@@ -125,17 +125,16 @@ int UTIL_CTX_set_ui_method(UTIL_CTX *ctx, UI_METHOD *ui_method, void *ui_data)
125125
126126static int UTIL_CTX_enumerate_slots_unlocked (UTIL_CTX * ctx )
127127{
128- if (!ctx -> pkcs11_ctx )
129- UTIL_CTX_init_libp11 (ctx );
130- if (!ctx -> pkcs11_ctx )
131- return -1 ;
132-
133128 /* PKCS11_update_slots() uses C_GetSlotList() via libp11 */
134129 if (PKCS11_update_slots (ctx -> pkcs11_ctx , & ctx -> slot_list , & ctx -> slot_count ) < 0 ) {
135- UTIL_CTX_log (ctx , LOG_INFO , "Failed to enumerate slots\n" );
130+ UTIL_CTX_log (ctx , LOG_ERR , "Failed to enumerate slots\n" );
131+ return 0 ;
132+ }
133+ if (ctx -> slot_count < 1 ) {
134+ UTIL_CTX_log (ctx , LOG_ERR , "No slot found\n" );
136135 return 0 ;
137136 }
138- UTIL_CTX_log (ctx , LOG_NOTICE , "Found %u slot%s\n" , ctx -> slot_count ,
137+ UTIL_CTX_log (ctx , LOG_INFO , "Found %u slot%s\n" , ctx -> slot_count ,
139138 ctx -> slot_count <= 1 ? "" : "s" );
140139 return 1 ;
141140}
@@ -145,7 +144,10 @@ int UTIL_CTX_enumerate_slots(UTIL_CTX *ctx)
145144 int rv ;
146145
147146 pthread_mutex_lock (& ctx -> lock );
148- rv = UTIL_CTX_enumerate_slots_unlocked (ctx );
147+ if (ctx -> pkcs11_ctx )
148+ rv = UTIL_CTX_enumerate_slots_unlocked (ctx );
149+ else
150+ rv = UTIL_CTX_init_libp11 (ctx ) == 0 ;
149151 pthread_mutex_unlock (& ctx -> lock );
150152 return rv ;
151153}
0 commit comments