chiark / gitweb /
gnupg2 (2.1.17-3) unstable; urgency=medium
[gnupg2.git] / debian / patches / dirmngr-idling / 0005-dirmngr-Drop-useless-housekeeping.patch
1 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2 Date: Sat, 29 Oct 2016 02:15:08 -0400
3 Subject: dirmngr: Drop useless housekeeping.
4
5 * dirmngr/dirmngr.c (handle_tick, time_for_housekeeping_p,
6 housekeeping_thread): Remove, no longer needed.
7 (handle_connections): Drop any attempt at a timeout, since no
8 housekeeping is necessary.
9
10 --
11
12 The housekeeping thread no longer does anything, and the main loop was
13 waking up every 60 seconds for no good reason.  The code is simpler
14 and the runtime is more efficient if we drop this.
15
16 Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
17 ---
18  dirmngr/dirmngr.c | 113 +++---------------------------------------------------
19  1 file changed, 5 insertions(+), 108 deletions(-)
20
21 diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c
22 index 58a424e8c..0b8bb02e6 100644
23 --- a/dirmngr/dirmngr.c
24 +++ b/dirmngr/dirmngr.c
25 @@ -304,13 +304,6 @@ static int active_connections;
26   * thread to run background network tasks.  */
27  static int network_activity_seen;
28  
29 -/* The timer tick used for housekeeping stuff.  */
30 -#define TIMERTICK_INTERVAL         (60)
31 -
32 -/* How oft to run the housekeeping.  */
33 -#define HOUSEKEEPING_INTERVAL      (600)
34 -
35 -
36  /* This union is used to avoid compiler warnings in case a pointer is
37     64 bit and an int 32 bit.  We store an integer in a pointer and get
38     it back later (npth_getspecific et al.).  */
39 @@ -1768,83 +1761,6 @@ handle_signal (int signo)
40  #endif /*!HAVE_W32_SYSTEM*/
41  
42  
43 -/* Thread to do the housekeeping.  */
44 -static void *
45 -housekeeping_thread (void *arg)
46 -{
47 -  static int sentinel;
48 -
49 -  (void)arg;
50 -
51 -  if (sentinel)
52 -    {
53 -      log_info ("housekeeping is already going on\n");
54 -      return NULL;
55 -    }
56 -  sentinel++;
57 -  if (opt.verbose > 1)
58 -    log_info ("starting housekeeping\n");
59 -
60 -  if (opt.verbose > 1)
61 -    log_info ("ready with housekeeping\n");
62 -  sentinel--;
63 -  return NULL;
64 -
65 -}
66 -
67 -
68 -#if GPGRT_GCC_HAVE_PUSH_PRAGMA
69 -# pragma GCC push_options
70 -# pragma GCC optimize ("no-strict-overflow")
71 -#endif
72 -static int
73 -time_for_housekeeping_p (time_t curtime)
74 -{
75 -  static time_t last_housekeeping;
76 -
77 -  if (!last_housekeeping)
78 -    last_housekeeping = curtime;
79 -
80 -  if (last_housekeeping + HOUSEKEEPING_INTERVAL <= curtime
81 -      || last_housekeeping > curtime /*(be prepared for y2038)*/)
82 -    {
83 -      last_housekeeping = curtime;
84 -      return 1;
85 -    }
86 -  return 0;
87 -}
88 -#if GPGRT_GCC_HAVE_PUSH_PRAGMA
89 -# pragma GCC pop_options
90 -#endif
91 -
92 -
93 -/* This is the worker for the ticker.  It is called every few seconds
94 -   and may only do fast operations. */
95 -static void
96 -handle_tick (void)
97 -{
98 -  if (time_for_housekeeping_p (gnupg_get_time ()))
99 -    {
100 -      npth_t thread;
101 -      npth_attr_t tattr;
102 -      int err;
103 -
104 -      err = npth_attr_init (&tattr);
105 -      if (err)
106 -        log_error ("error preparing housekeeping thread: %s\n", strerror (err));
107 -      else
108 -        {
109 -          npth_attr_setdetachstate (&tattr, NPTH_CREATE_DETACHED);
110 -          err = npth_create (&thread, &tattr, housekeeping_thread, NULL);
111 -          if (err)
112 -            log_error ("error spawning housekeeping thread: %s\n",
113 -                       strerror (err));
114 -          npth_attr_destroy (&tattr);
115 -        }
116 -    }
117 -}
118 -
119 -
120  /* Check the nonce on a new connection.  This is a NOP unless we are
121     using our Unix domain socket emulation under Windows.  */
122  static int
123 @@ -1945,9 +1861,6 @@ handle_connections (assuan_fd_t listen_fd)
124    gnupg_fd_t fd;
125    int nfd, ret;
126    fd_set fdset, read_fdset;
127 -  struct timespec abstime;
128 -  struct timespec curtime;
129 -  struct timespec timeout;
130    int saved_errno;
131    int my_inotify_fd = -1;
132  
133 @@ -1987,9 +1900,7 @@ handle_connections (assuan_fd_t listen_fd)
134  #endif /*HAVE_INOTIFY_INIT*/
135  
136  
137 -  /* Setup the fdset.  It has only one member.  This is because we use
138 -     pth_select instead of pth_accept to properly sync timeouts with
139 -     to full second.  */
140 +  /* Setup the fdset.  */
141    FD_ZERO (&fdset);
142    FD_SET (FD2INT (listen_fd), &fdset);
143    nfd = FD2INT (listen_fd);
144 @@ -2000,9 +1911,6 @@ handle_connections (assuan_fd_t listen_fd)
145          nfd = my_inotify_fd;
146      }
147  
148 -  npth_clock_gettime (&abstime);
149 -  abstime.tv_sec += TIMERTICK_INTERVAL;
150 -
151    /* Main loop.  */
152    for (;;)
153      {
154 @@ -2013,7 +1921,7 @@ handle_connections (assuan_fd_t listen_fd)
155              break; /* ready */
156  
157            /* Do not accept new connections but keep on running the
158 -           * loop to cope with the timer events.
159 +           * select loop to wait for signals (e.g. SIGCHLD).
160             *
161             * Note that we do not close the listening socket because a
162             * client trying to connect to that socket would instead
163 @@ -2033,24 +1941,14 @@ handle_connections (assuan_fd_t listen_fd)
164        /* Take a copy of the fdset.  */
165        read_fdset = fdset;
166  
167 -      npth_clock_gettime (&curtime);
168 -      if (!(npth_timercmp (&curtime, &abstime, <)))
169 -       {
170 -         /* Timeout.  */
171 -         handle_tick ();
172 -         npth_clock_gettime (&abstime);
173 -         abstime.tv_sec += TIMERTICK_INTERVAL;
174 -       }
175 -      npth_timersub (&abstime, &curtime, &timeout);
176 -
177  #ifndef HAVE_W32_SYSTEM
178 -      ret = npth_pselect (nfd+1, &read_fdset, NULL, NULL, &timeout, npth_sigev_sigmask());
179 +      ret = npth_pselect (nfd+1, &read_fdset, NULL, NULL, NULL, npth_sigev_sigmask());
180        saved_errno = errno;
181  
182        while (npth_sigev_get_pending(&signo))
183         handle_signal (signo);
184  #else
185 -      ret = npth_eselect (nfd+1, &read_fdset, NULL, NULL, &timeout, NULL, NULL);
186 +      ret = npth_eselect (nfd+1, &read_fdset, NULL, NULL, NULL, NULL, NULL);
187        saved_errno = errno;
188  #endif
189  
190 @@ -2064,8 +1962,7 @@ handle_connections (assuan_fd_t listen_fd)
191  
192        if (ret <= 0)
193          {
194 -          /* Interrupt or timeout.  Will be handled when calculating the
195 -             next timeout.  */
196 +          /* Interrupt.  Will be handled at the top of the next loop.  */
197            continue;
198          }
199