diff options
author | NIIBE Yutaka <[email protected]> | 2018-11-27 02:08:51 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2018-11-27 02:08:51 +0000 |
commit | 483e63f9b5faead819ddd28308902ef43bf298ab (patch) | |
tree | 3b18688a6ba5bc4f41769c9196ac0e5145d1ed02 /agent/call-scd.c | |
parent | w32: Fix linkage of gpg-pair-tool (diff) | |
download | gnupg-483e63f9b5faead819ddd28308902ef43bf298ab.tar.gz gnupg-483e63f9b5faead819ddd28308902ef43bf298ab.zip |
agent: Better serialization for scdaemon access.
* agent/call-scd.c (unlock_scd): Move lock before accessing IN_USE.
(wait_child_thread): Add log_info for Windows, and fixed log_error
message.
--
The old code is still valid with cooperate threads, but this is
better.
Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'agent/call-scd.c')
-rw-r--r-- | agent/call-scd.c | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/agent/call-scd.c b/agent/call-scd.c index c6d062a02..796e7d86e 100644 --- a/agent/call-scd.c +++ b/agent/call-scd.c @@ -169,29 +169,25 @@ unlock_scd (ctrl_t ctrl, int rc) if (!rc) rc = gpg_error (GPG_ERR_INTERNAL); } + err = npth_mutex_lock (&start_scd_lock); + if (err) + { + log_error ("failed to acquire the start_scd lock: %s\n", strerror (err)); + return gpg_error (GPG_ERR_INTERNAL); + } ctrl->scd_local->in_use = 0; if (ctrl->scd_local->invalid) { - err = npth_mutex_lock (&start_scd_lock); - if (err) - { - log_error ("failed to acquire the start_scd lock: %s\n", - strerror (err)); - return gpg_error (GPG_ERR_INTERNAL); - } - assuan_release (ctrl->scd_local->ctx); ctrl->scd_local->ctx = NULL; - - err = npth_mutex_unlock (&start_scd_lock); - if (err) - { - log_error ("failed to release the start_scd lock: %s\n", - strerror (err)); - return gpg_error (GPG_ERR_INTERNAL); - } + ctrl->scd_local->invalid = 0; + } + err = npth_mutex_unlock (&start_scd_lock); + if (err) + { + log_error ("failed to release the start_scd lock: %s\n", strerror (err)); + return gpg_error (GPG_ERR_INTERNAL); } - ctrl->scd_local->invalid = 0; return rc; } @@ -219,6 +215,7 @@ wait_child_thread (void *arg) npth_unprotect (); WaitForSingleObject ((HANDLE)pid, INFINITE); npth_protect (); + log_info ("scdaemon finished\n"); #else int wstatus; pid_t pid = (pid_t)(uintptr_t)arg; @@ -278,8 +275,8 @@ wait_child_thread (void *arg) err = npth_mutex_unlock (&start_scd_lock); if (err) - log_error ("failed to release the start_scd lock while" - " doing the aliveness check: %s\n", strerror (err)); + log_error ("failed to release the start_scd lock after waitpid", + strerror (err)); } return NULL; |