aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2021-05-14 03:38:06 +0000
committerNIIBE Yutaka <[email protected]>2021-05-14 03:38:06 +0000
commit8640f66b908e49e98958781f93d94988a144d2a0 (patch)
tree123dd23fbf23045922d869b2cfa493dbaf83c086
parentscd: Change the exit condition of pcsc_thread. (diff)
downloadgnupg-8640f66b908e49e98958781f93d94988a144d2a0.tar.gz
gnupg-8640f66b908e49e98958781f93d94988a144d2a0.zip
scd: Fix possible race for watching thread doesn't exit.
* scd/apdu.c (release_pcsc_context): Synchronize the exit. (pcsc_init): Use joinable thread. Signed-off-by: NIIBE Yutaka <[email protected]>
-rw-r--r--scd/apdu.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/scd/apdu.c b/scd/apdu.c
index 6420b5a05..0d7ee777d 100644
--- a/scd/apdu.c
+++ b/scd/apdu.c
@@ -85,6 +85,7 @@ typedef unsigned long pcsc_dword_t;
/* PC/SC context to access readers. Shared among all readers. */
static struct pcsc_global_data {
HANDLE context;
+ npth_t thread;
int count;
const char *rdrname[MAX_READER];
} pcsc;
@@ -786,10 +787,19 @@ control_pcsc (int slot, pcsc_dword_t ioctl_code,
static void
release_pcsc_context (void)
{
+ int err;
+
/*log_debug ("%s: releasing context\n", __func__);*/
log_assert (pcsc.context != 0);
pcsc_release_context (pcsc.context);
pcsc.context = 0;
+
+ npth_mutex_unlock (&reader_table_lock);
+ err = npth_join (pcsc.thread, NULL);
+ if (err)
+ log_error ("release_pcsc_context: error joining thread: %s\n", strerror (err));
+ pcsc.thread = 0;
+ npth_mutex_lock (&reader_table_lock);
}
static int
@@ -1273,7 +1283,6 @@ pcsc_init (void)
}
else
{
- npth_t thread;
npth_attr_t tattr;
int err_npth;
@@ -1284,8 +1293,8 @@ pcsc_init (void)
return -1;
}
- npth_attr_setdetachstate (&tattr, NPTH_CREATE_DETACHED);
- err_npth = npth_create (&thread, &tattr, pcsc_thread, NULL);
+ npth_attr_setdetachstate (&tattr, NPTH_CREATE_JOINABLE);
+ err_npth = npth_create (&pcsc.thread, &tattr, pcsc_thread, NULL);
if (err_npth)
{
log_error ("npth_create failed: %s\n", strerror (err_npth));