chiark / gitweb /
gpg agent threading bugs: Add some `xxx' comments.
[gnupg2.git] / dirmngr / dirmngr.c
index 5ee589e933ebf83f330b055d211cff25cf1cf51d..5abfe78c6e75752416a1c8be3c3434c73b659d1b 100644 (file)
@@ -304,13 +304,6 @@ static int active_connections;
  * thread to run background network tasks.  */
 static int network_activity_seen;
 
-/* The timer tick used for housekeeping stuff.  */
-#define TIMERTICK_INTERVAL         (60)
-
-/* How oft to run the housekeeping.  */
-#define HOUSEKEEPING_INTERVAL      (600)
-
-
 /* This union is used to avoid compiler warnings in case a pointer is
    64 bit and an int 32 bit.  We store an integer in a pointer and get
    it back later (npth_getspecific et al.).  */
@@ -481,6 +474,9 @@ set_tor_mode (void)
 {
   if (opt.use_tor)
     {
+      /* Enable Tor mode and when called again force a new curcuit
+       * (e.g. on SIGHUP).  */
+      enable_dns_tormode (1);
       if (assuan_sock_set_flag (ASSUAN_INVALID_FD, "tor-mode", 1))
         {
           log_error ("error enabling Tor mode: %s\n", strerror (errno));
@@ -919,13 +915,6 @@ main (int argc, char **argv)
   log_info ("NOTE: this is a development version!\n");
 #endif
 
-  if (opt.use_tor)
-    {
-      log_info ("WARNING: ***************************************\n");
-      log_info ("WARNING: Tor mode (--use-tor) MAY NOT FULLY WORK!\n");
-      log_info ("WARNING: ***************************************\n");
-    }
-
   /* Print a warning if an argument looks like an option.  */
   if (!opt.quiet && !(pargs.flags & ARGPARSE_FLAG_STOP_SEEN))
     {
@@ -1768,99 +1757,6 @@ handle_signal (int signo)
 #endif /*!HAVE_W32_SYSTEM*/
 
 
-/* Thread to do the housekeeping.  */
-static void *
-housekeeping_thread (void *arg)
-{
-  static int sentinel;
-  time_t curtime;
-  struct server_control_s ctrlbuf;
-
-  (void)arg;
-
-  curtime = gnupg_get_time ();
-  if (sentinel)
-    {
-      log_info ("housekeeping is already going on\n");
-      return NULL;
-    }
-  sentinel++;
-  if (opt.verbose > 1)
-    log_info ("starting housekeeping\n");
-
-  memset (&ctrlbuf, 0, sizeof ctrlbuf);
-  dirmngr_init_default_ctrl (&ctrlbuf);
-
-  ks_hkp_housekeeping (curtime);
-  if (network_activity_seen)
-    {
-      network_activity_seen = 0;
-      if (opt.use_tor || opt.allow_version_check)
-        dirmngr_load_swdb (&ctrlbuf, 0);
-    }
-
-  dirmngr_deinit_default_ctrl (&ctrlbuf);
-
-  if (opt.verbose > 1)
-    log_info ("ready with housekeeping\n");
-  sentinel--;
-  return NULL;
-
-}
-
-
-#if GPGRT_GCC_HAVE_PUSH_PRAGMA
-# pragma GCC push_options
-# pragma GCC optimize ("no-strict-overflow")
-#endif
-static int
-time_for_housekeeping_p (time_t curtime)
-{
-  static time_t last_housekeeping;
-
-  if (!last_housekeeping)
-    last_housekeeping = curtime;
-
-  if (last_housekeeping + HOUSEKEEPING_INTERVAL <= curtime
-      || last_housekeeping > curtime /*(be prepared for y2038)*/)
-    {
-      last_housekeeping = curtime;
-      return 1;
-    }
-  return 0;
-}
-#if GPGRT_GCC_HAVE_PUSH_PRAGMA
-# pragma GCC pop_options
-#endif
-
-
-/* This is the worker for the ticker.  It is called every few seconds
-   and may only do fast operations. */
-static void
-handle_tick (void)
-{
-  if (time_for_housekeeping_p (gnupg_get_time ()))
-    {
-      npth_t thread;
-      npth_attr_t tattr;
-      int err;
-
-      err = npth_attr_init (&tattr);
-      if (err)
-        log_error ("error preparing housekeeping thread: %s\n", strerror (err));
-      else
-        {
-          npth_attr_setdetachstate (&tattr, NPTH_CREATE_DETACHED);
-          err = npth_create (&thread, &tattr, housekeeping_thread, NULL);
-          if (err)
-            log_error ("error spawning housekeeping thread: %s\n",
-                       strerror (err));
-          npth_attr_destroy (&tattr);
-        }
-    }
-}
-
-
 /* Check the nonce on a new connection.  This is a NOP unless we are
    using our Unix domain socket emulation under Windows.  */
 static int
@@ -1961,9 +1857,6 @@ handle_connections (assuan_fd_t listen_fd)
   gnupg_fd_t fd;
   int nfd, ret;
   fd_set fdset, read_fdset;
-  struct timespec abstime;
-  struct timespec curtime;
-  struct timespec timeout;
   int saved_errno;
   int my_inotify_fd = -1;
 
@@ -2003,9 +1896,7 @@ handle_connections (assuan_fd_t listen_fd)
 #endif /*HAVE_INOTIFY_INIT*/
 
 
-  /* Setup the fdset.  It has only one member.  This is because we use
-     pth_select instead of pth_accept to properly sync timeouts with
-     to full second.  */
+  /* Setup the fdset.  */
   FD_ZERO (&fdset);
   FD_SET (FD2INT (listen_fd), &fdset);
   nfd = FD2INT (listen_fd);
@@ -2016,9 +1907,6 @@ handle_connections (assuan_fd_t listen_fd)
         nfd = my_inotify_fd;
     }
 
-  npth_clock_gettime (&abstime);
-  abstime.tv_sec += TIMERTICK_INTERVAL;
-
   /* Main loop.  */
   for (;;)
     {
@@ -2029,7 +1917,7 @@ handle_connections (assuan_fd_t listen_fd)
             break; /* ready */
 
           /* Do not accept new connections but keep on running the
-           * loop to cope with the timer events.
+           * select loop to wait for signals (e.g. SIGCHLD).
            *
            * Note that we do not close the listening socket because a
            * client trying to connect to that socket would instead
@@ -2049,24 +1937,14 @@ handle_connections (assuan_fd_t listen_fd)
       /* Take a copy of the fdset.  */
       read_fdset = fdset;
 
-      npth_clock_gettime (&curtime);
-      if (!(npth_timercmp (&curtime, &abstime, <)))
-       {
-         /* Timeout.  */
-         handle_tick ();
-         npth_clock_gettime (&abstime);
-         abstime.tv_sec += TIMERTICK_INTERVAL;
-       }
-      npth_timersub (&abstime, &curtime, &timeout);
-
 #ifndef HAVE_W32_SYSTEM
-      ret = npth_pselect (nfd+1, &read_fdset, NULL, NULL, &timeout, npth_sigev_sigmask());
+      ret = npth_pselect (nfd+1, &read_fdset, NULL, NULL, NULL, npth_sigev_sigmask());
       saved_errno = errno;
 
       while (npth_sigev_get_pending(&signo))
        handle_signal (signo);
 #else
-      ret = npth_eselect (nfd+1, &read_fdset, NULL, NULL, &timeout, NULL, NULL);
+      ret = npth_eselect (nfd+1, &read_fdset, NULL, NULL, NULL, NULL, NULL);
       saved_errno = errno;
 #endif
 
@@ -2080,8 +1958,7 @@ handle_connections (assuan_fd_t listen_fd)
 
       if (ret <= 0)
         {
-          /* Interrupt or timeout.  Will be handled when calculating the
-             next timeout.  */
+          /* Interrupt.  Will be handled at the top of the next loop.  */
           continue;
         }