aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2024-06-11 06:21:19 +0000
committerWerner Koch <[email protected]>2024-07-01 12:13:10 +0000
commitc868d23f6180ae3e4b27292239f50b7f05f05b89 (patch)
tree9433c3585ec11b72cca808f2a904d9be339aa23a
parentgpg-mail-tube: New utility. (diff)
downloadgnupg-c868d23f6180ae3e4b27292239f50b7f05f05b89.tar.gz
gnupg-c868d23f6180ae3e4b27292239f50b7f05f05b89.zip
agent: Fix a race condition which results accessing finished scd.
* agent/call-daemon.c (daemon_start): Decision of connection/reuse of CTX and assignment to ->ctx should be done with the lock. -- When scdaemon is exiting and agent tries to spawn/connect/reconnect, there is a race condition between detecting finish of scd and spawn/connect/reconnect. Signed-off-by: NIIBE Yutaka <[email protected]> (cherry picked from commit 563bfbb0be4ebbc85bc56426541f666839e6aa13)
-rw-r--r--agent/call-daemon.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/agent/call-daemon.c b/agent/call-daemon.c
index e1c5669e9..f200af28f 100644
--- a/agent/call-daemon.c
+++ b/agent/call-daemon.c
@@ -511,13 +511,12 @@ daemon_start (enum daemon_type type, ctrl_t ctrl)
}
leave:
- rc = npth_mutex_unlock (&start_daemon_lock);
- if (rc)
- log_error ("failed to release the start_daemon lock: %s\n", strerror (rc));
-
xfree (abs_homedir);
if (err)
{
+ rc = npth_mutex_unlock (&start_daemon_lock);
+ if (rc)
+ log_error ("failed to release the start_daemon lock: %s\n", strerror (rc));
daemon_unlock (type, ctrl, err);
if (ctx)
assuan_release (ctx);
@@ -526,6 +525,9 @@ daemon_start (enum daemon_type type, ctrl_t ctrl)
{
ctrl->d_local[type]->ctx = ctx;
ctrl->d_local[type]->invalid = 0;
+ rc = npth_mutex_unlock (&start_daemon_lock);
+ if (rc)
+ log_error ("failed to release the start_daemon lock: %s\n", strerror (rc));
}
return err;
}