aboutsummaryrefslogtreecommitdiffstats
path: root/agent/cache.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2023-08-30 05:48:56 +0000
committerNIIBE Yutaka <[email protected]>2023-08-30 05:48:56 +0000
commit76a2f180286e6cb10fd7075994512a0028d4eb2c (patch)
tree720c82bcc10442e211a14473886e561ed86480c5 /agent/cache.c
parentagent: Have a thread monitoring parent PID and homedir. (diff)
downloadgnupg-76a2f180286e6cb10fd7075994512a0028d4eb2c.tar.gz
gnupg-76a2f180286e6cb10fd7075994512a0028d4eb2c.zip
agent: Better interaction between main loop and cache expiration.
* agent/agent.h (agent_cache_housekeeping): Remove. (agent_cache_expiration): New. * agent/cache.c (agent_cache_housekeeping): Remove. (agent_cache_expiration): New. * agent/gpg-agent.c (TIMERTICK_INTERVAL): Remove. (handle_tick): Remove. (handle_connections): Call agent_cache_expiration and use the timeout value determined by the call. -- GnuPG-bug-id: 6681 Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'agent/cache.c')
-rw-r--r--agent/cache.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/agent/cache.c b/agent/cache.c
index 7616dafc1..f900be6cc 100644
--- a/agent/cache.c
+++ b/agent/cache.c
@@ -270,23 +270,46 @@ housekeeping (void)
}
-void
-agent_cache_housekeeping (void)
+#define TIMERTICK_INTERVAL (4)
+struct timespec *
+agent_cache_expiration (void)
{
+ static struct timespec abstime;
+ static struct timespec timeout;
+ static int initialized = 0;
+ struct timespec curtime;
int res;
- if (DBG_CACHE)
- log_debug ("agent_cache_housekeeping\n");
+ if (!initialized)
+ {
+ initialized = 1;
+ npth_clock_gettime (&abstime);
+ abstime.tv_sec += TIMERTICK_INTERVAL;
+ }
- res = npth_mutex_lock (&cache_lock);
- if (res)
- log_fatal ("failed to acquire cache mutex: %s\n", strerror (res));
+ npth_clock_gettime (&curtime);
+ if (!(npth_timercmp (&curtime, &abstime, <)))
+ {
+ /* Timeout. */
+ npth_clock_gettime (&abstime);
+ abstime.tv_sec += TIMERTICK_INTERVAL;
- housekeeping ();
+ if (DBG_CACHE)
+ log_debug ("agent_cache_housekeeping\n");
- res = npth_mutex_unlock (&cache_lock);
- if (res)
- log_fatal ("failed to release cache mutex: %s\n", strerror (res));
+ res = npth_mutex_lock (&cache_lock);
+ if (res)
+ log_fatal ("failed to acquire cache mutex: %s\n", strerror (res));
+
+ housekeeping ();
+
+ res = npth_mutex_unlock (&cache_lock);
+ if (res)
+ log_fatal ("failed to release cache mutex: %s\n", strerror (res));
+ }
+
+ npth_timersub (&abstime, &curtime, &timeout);
+ return &timeout;
}