From d50c2eff8d6931586c527edb3dea98dbc6facdec Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 26 Jul 2017 10:02:52 +0200 Subject: agent,dirmngr: Check for homedir removal also using stat(2). * agent/gpg-agent.c (have_homedir_inotify): New var. (reliable_homedir_inotify): New var. (main): Set reliable_homedir_inotify. (handle_tick): Call stat on the homedir. (handle_connections): Mark availibility of the inotify watch. * dirmngr/dirmngr.c (handle_tick): Call stat on the homedir. (TIMERTICK_INTERVAL_SHUTDOWN): New. (handle_connections): Depend tick interval on the shutdown state. -- The stat call is used on systems which do not support inotify and also when we assume that the inotify does not work reliable. Signed-off-by: Werner Koch --- dirmngr/dirmngr.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'dirmngr/dirmngr.c') diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c index 5f3a4cd18..1ddc568a0 100644 --- a/dirmngr/dirmngr.c +++ b/dirmngr/dirmngr.c @@ -334,8 +334,9 @@ static int network_activity_seen; static strlist_t hkp_cacert_filenames; -/* The timer tick used for housekeeping stuff. */ -#define TIMERTICK_INTERVAL (60) +/* The timer tick used for housekeeping stuff. The second constant is used when a shutdown is pending. */ +#define TIMERTICK_INTERVAL (60) +#define TIMERTICK_INTERVAL_SHUTDOWN (4) /* How oft to run the housekeeping. */ #define HOUSEKEEPING_INTERVAL (600) @@ -1967,6 +1968,8 @@ time_for_housekeeping_p (time_t curtime) static void handle_tick (void) { + struct stat statbuf; + if (time_for_housekeeping_p (gnupg_get_time ())) { npth_t thread; @@ -1986,6 +1989,14 @@ handle_tick (void) npth_attr_destroy (&tattr); } } + + /* Check whether the homedir is still available. */ + if (!shutdown_pending + && stat (gnupg_homedir (), &statbuf) && errno == ENOENT) + { + shutdown_pending = 1; + log_info ("homedir has been removed - shutting down\n"); + } } @@ -2179,10 +2190,13 @@ handle_connections (assuan_fd_t listen_fd) npth_clock_gettime (&curtime); if (!(npth_timercmp (&curtime, &abstime, <))) { - /* Timeout. */ + /* Timeout. When a shutdown is pending we use a shorter + * interval to handle the shutdown more quickly. */ handle_tick (); npth_clock_gettime (&abstime); - abstime.tv_sec += TIMERTICK_INTERVAL; + abstime.tv_sec += (shutdown_pending + ? TIMERTICK_INTERVAL_SHUTDOWN + : TIMERTICK_INTERVAL); } npth_timersub (&abstime, &curtime, &timeout); -- cgit v1.2.3