1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-04-17 15:44:34 +02:00

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 <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2018-11-27 11:08:51 +09:00
parent f12fcd9079
commit 483e63f9b5

View File

@ -169,29 +169,25 @@ unlock_scd (ctrl_t ctrl, int rc)
if (!rc) if (!rc)
rc = gpg_error (GPG_ERR_INTERNAL); 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; ctrl->scd_local->in_use = 0;
if (ctrl->scd_local->invalid) 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); assuan_release (ctrl->scd_local->ctx);
ctrl->scd_local->ctx = NULL; ctrl->scd_local->ctx = NULL;
ctrl->scd_local->invalid = 0;
err = npth_mutex_unlock (&start_scd_lock); }
if (err) err = npth_mutex_unlock (&start_scd_lock);
{ if (err)
log_error ("failed to release the start_scd lock: %s\n", {
strerror (err)); log_error ("failed to release the start_scd lock: %s\n", strerror (err));
return gpg_error (GPG_ERR_INTERNAL); return gpg_error (GPG_ERR_INTERNAL);
}
} }
ctrl->scd_local->invalid = 0;
return rc; return rc;
} }
@ -219,6 +215,7 @@ wait_child_thread (void *arg)
npth_unprotect (); npth_unprotect ();
WaitForSingleObject ((HANDLE)pid, INFINITE); WaitForSingleObject ((HANDLE)pid, INFINITE);
npth_protect (); npth_protect ();
log_info ("scdaemon finished\n");
#else #else
int wstatus; int wstatus;
pid_t pid = (pid_t)(uintptr_t)arg; pid_t pid = (pid_t)(uintptr_t)arg;
@ -278,8 +275,8 @@ wait_child_thread (void *arg)
err = npth_mutex_unlock (&start_scd_lock); err = npth_mutex_unlock (&start_scd_lock);
if (err) if (err)
log_error ("failed to release the start_scd lock while" log_error ("failed to release the start_scd lock after waitpid",
" doing the aliveness check: %s\n", strerror (err)); strerror (err));
} }
return NULL; return NULL;