]> git.decadent.org.uk Git - odhcp6c.git/blob - src/odhcp6c.c
Add user-class option in help text and minor clean up
[odhcp6c.git] / src / odhcp6c.c
1 /**
2  * Copyright (C) 2012-2014 Steven Barth <steven@midlink.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License v2 as published by
6  * the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  */
14
15 #include <time.h>
16 #include <errno.h>
17 #include <fcntl.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <stddef.h>
21 #include <unistd.h>
22 #include <syslog.h>
23 #include <signal.h>
24 #include <string.h>
25 #include <stdbool.h>
26
27 #include <net/if.h>
28 #include <sys/wait.h>
29 #include <sys/syscall.h>
30 #include <arpa/inet.h>
31
32 #include "odhcp6c.h"
33 #include "ra.h"
34
35 #ifdef EXT_BFD_PING
36 #include "bfd.h"
37 #endif
38
39
40 static void sighandler(int signal);
41 static int usage(void);
42
43 static uint8_t *state_data[_STATE_MAX] = {NULL};
44 static size_t state_len[_STATE_MAX] = {0};
45
46 static volatile bool signal_io = false;
47 static volatile bool signal_usr1 = false;
48 static volatile bool signal_usr2 = false;
49 static volatile bool signal_term = false;
50
51 static int urandom_fd = -1, allow_slaac_only = 0;
52 static bool bound = false, release = true;
53 static time_t last_update = 0;
54
55 static unsigned int min_update_interval = DEFAULT_MIN_UPDATE_INTERVAL;
56
57 int main(_unused int argc, char* const argv[])
58 {
59         // Allocate ressources
60         const char *pidfile = NULL;
61         const char *script = "/usr/sbin/odhcp6c-update";
62         ssize_t l;
63         uint8_t buf[134];
64         char *optpos;
65         uint16_t opttype;
66         uint16_t optlen;
67         enum odhcp6c_ia_mode ia_na_mode = IA_MODE_TRY;
68         enum odhcp6c_ia_mode ia_pd_mode = IA_MODE_NONE;
69         int ia_pd_iaid_index = 0;
70         static struct in6_addr ifid = IN6ADDR_ANY_INIT;
71         int sol_timeout = DHCPV6_SOL_MAX_RT;
72
73 #ifdef EXT_BFD_PING
74         int bfd_interval = 0, bfd_loss = 3;
75 #endif
76
77         bool help = false, daemonize = false;
78         int logopt = LOG_PID;
79         int c;
80         unsigned int client_options = DHCPV6_CLIENT_FQDN | DHCPV6_ACCEPT_RECONFIGURE;
81
82         while ((c = getopt(argc, argv, "S::N:V:P:FB:c:i:r:Ru:s:kt:m:hedp:fa")) != -1) {
83                 switch (c) {
84                 case 'S':
85                         allow_slaac_only = (optarg) ? atoi(optarg) : -1;
86                         break;
87
88                 case 'N':
89                         if (!strcmp(optarg, "force")) {
90                                 ia_na_mode = IA_MODE_FORCE;
91                                 allow_slaac_only = -1;
92                         } else if (!strcmp(optarg, "none")) {
93                                 ia_na_mode = IA_MODE_NONE;
94                         } else if (!strcmp(optarg, "try")) {
95                                 ia_na_mode = IA_MODE_TRY;
96                         } else{
97                                 help = true;
98                         }
99                         break;
100
101                 case 'V':
102                         l = script_unhexlify(buf, sizeof(buf), optarg);
103                         if (!l)
104                                 help=true;
105
106                         odhcp6c_add_state(STATE_VENDORCLASS, buf, l);
107
108                         break;
109                 case 'P':
110                         if (ia_pd_mode == IA_MODE_NONE)
111                                 ia_pd_mode = IA_MODE_TRY;
112
113                         if (allow_slaac_only >= 0 && allow_slaac_only < 10)
114                                 allow_slaac_only = 10;
115
116                         char *iaid_begin;
117                         int iaid_len = 0;
118
119                         int prefix_length = strtoul(optarg, &iaid_begin, 10);
120
121                         if (*iaid_begin != '\0' && *iaid_begin != ',' && *iaid_begin != ':') {
122                                 syslog(LOG_ERR, "invalid argument: '%s'", optarg);
123                                 return 1;
124                         }
125
126                         struct odhcp6c_request_prefix prefix = { 0, prefix_length };
127
128                         if (*iaid_begin == ',' && (iaid_len = strlen(iaid_begin)) > 1)
129                                 memcpy(&prefix.iaid, iaid_begin + 1, iaid_len > 4 ? 4 : iaid_len);
130                         else if (*iaid_begin == ':')
131                                 prefix.iaid = htonl((uint32_t)strtoul(&iaid_begin[1], NULL, 16));
132                         else
133                                 prefix.iaid = htonl(++ia_pd_iaid_index);
134
135                         odhcp6c_add_state(STATE_IA_PD_INIT, &prefix, sizeof(prefix));
136
137                         break;
138
139                 case 'F':
140                         allow_slaac_only = -1;
141                         ia_pd_mode = IA_MODE_FORCE;
142                         break;
143
144 #ifdef EXT_BFD_PING
145                 case 'B':
146                         bfd_interval = atoi(optarg);
147                         break;
148 #endif
149
150                 case 'c':
151                         l = script_unhexlify(&buf[4], sizeof(buf) - 4, optarg);
152                         if (l > 0) {
153                                 buf[0] = 0;
154                                 buf[1] = DHCPV6_OPT_CLIENTID;
155                                 buf[2] = 0;
156                                 buf[3] = l;
157                                 odhcp6c_add_state(STATE_CLIENT_ID, buf, l + 4);
158                         } else {
159                                 help = true;
160                         }
161                         break;
162
163                 case 'i':
164                         if (inet_pton(AF_INET6, optarg, &ifid) != 1)
165                                 help = true;
166                         break;
167
168                 case 'r':
169                         optpos = optarg;
170                         while (optpos[0]) {
171                                 opttype = htons(strtoul(optarg, &optpos, 10));
172                                 if (optpos == optarg)
173                                         break;
174                                 else if (optpos[0])
175                                         optarg = &optpos[1];
176                                 odhcp6c_add_state(STATE_ORO, &opttype, 2);
177                         }
178                         break;
179
180                 case 'R':
181                         client_options |= DHCPV6_STRICT_OPTIONS;
182                         break;
183
184                 case 'u':
185                         optlen = htons(strlen(optarg));
186                         odhcp6c_add_state(STATE_USERCLASS, &optlen, 2);
187                         odhcp6c_add_state(STATE_USERCLASS, optarg, strlen(optarg));
188                         break;
189
190                 case 's':
191                         script = optarg;
192                         break;
193
194                 case 'k':
195                         release = false;
196                         break;
197
198                 case 't':
199                         sol_timeout = atoi(optarg);
200                         break;
201
202                 case 'm':
203                         min_update_interval = atoi(optarg);
204                         break;
205
206                 case 'e':
207                         logopt |= LOG_PERROR;
208                         break;
209
210                 case 'd':
211                         daemonize = true;
212                         break;
213
214                 case 'p':
215                         pidfile = optarg;
216                         break;
217
218                 case 'f':
219                         client_options &= ~DHCPV6_CLIENT_FQDN;
220                         break;
221
222                 case 'a':
223                         client_options &= ~DHCPV6_ACCEPT_RECONFIGURE;
224                         break;
225
226                 default:
227                         help = true;
228                         break;
229                 }
230         }
231
232         openlog("odhcp6c", logopt, LOG_DAEMON);
233         const char *ifname = argv[optind];
234
235         if (help || !ifname)
236                 return usage();
237
238         signal(SIGIO, sighandler);
239         signal(SIGHUP, sighandler);
240         signal(SIGINT, sighandler);
241         signal(SIGCHLD, sighandler);
242         signal(SIGTERM, sighandler);
243         signal(SIGUSR1, sighandler);
244         signal(SIGUSR2, sighandler);
245
246         if ((urandom_fd = open("/dev/urandom", O_CLOEXEC | O_RDONLY)) < 0 ||
247                         init_dhcpv6(ifname, client_options, sol_timeout) ||
248                         ra_init(ifname, &ifid) || script_init(script, ifname)) {
249                 syslog(LOG_ERR, "failed to initialize: %s", strerror(errno));
250                 return 3;
251         }
252
253         if (daemonize) {
254                 openlog("odhcp6c", LOG_PID, LOG_DAEMON); // Disable LOG_PERROR
255                 if (daemon(0, 0)) {
256                         syslog(LOG_ERR, "Failed to daemonize: %s",
257                                         strerror(errno));
258                         return 4;
259                 }
260
261                 char pidbuf[128];
262                 if (!pidfile) {
263                         snprintf(pidbuf, sizeof(pidbuf),
264                                         "/var/run/odhcp6c.%s.pid", ifname);
265                         pidfile = pidbuf;
266                 }
267
268                 int fd = open(pidfile, O_WRONLY | O_CREAT, 0644);
269                 if (fd >= 0) {
270                         char buf[8];
271                         int len = snprintf(buf, sizeof(buf), "%i\n", getpid());
272                         write(fd, buf, len);
273                         close(fd);
274                 }
275         }
276
277         script_call("started");
278
279         while (!signal_term) { // Main logic
280                 odhcp6c_clear_state(STATE_SERVER_ID);
281                 odhcp6c_clear_state(STATE_IA_NA);
282                 odhcp6c_clear_state(STATE_IA_PD);
283                 odhcp6c_clear_state(STATE_SNTP_IP);
284                 odhcp6c_clear_state(STATE_NTP_IP);
285                 odhcp6c_clear_state(STATE_NTP_FQDN);
286                 odhcp6c_clear_state(STATE_SIP_IP);
287                 odhcp6c_clear_state(STATE_SIP_FQDN);
288                 dhcpv6_set_ia_mode(ia_na_mode, ia_pd_mode);
289                 bound = false;
290
291                 syslog(LOG_NOTICE, "(re)starting transaction on %s", ifname);
292
293                 signal_usr1 = signal_usr2 = false;
294                 int mode = dhcpv6_request(DHCPV6_MSG_SOLICIT);
295                 odhcp6c_signal_process();
296
297                 if (mode < 0)
298                         continue;
299
300                 do {
301                         int res = dhcpv6_request(mode == DHCPV6_STATELESS ?
302                                         DHCPV6_MSG_INFO_REQ : DHCPV6_MSG_REQUEST);
303                         bool signalled = odhcp6c_signal_process();
304
305                         if (res > 0)
306                                 break;
307                         else if (signalled) {
308                                 mode = -1;
309                                 break;
310                         }
311
312                         mode = dhcpv6_promote_server_cand();
313                 } while (mode > DHCPV6_UNKNOWN);
314
315                 if (mode < 0)
316                         continue;
317
318                 switch (mode) {
319                 case DHCPV6_STATELESS:
320                         bound = true;
321                         syslog(LOG_NOTICE, "entering stateless-mode on %s", ifname);
322
323                         while (!signal_usr2 && !signal_term) {
324                                 signal_usr1 = false;
325                                 script_call("informed");
326
327                                 int res = dhcpv6_poll_reconfigure();
328                                 odhcp6c_signal_process();
329
330                                 if (res > 0)
331                                         continue;
332
333                                 if (signal_usr1) {
334                                         signal_usr1 = false; // Acknowledged
335                                         continue;
336                                 }
337                                 if (signal_usr2 || signal_term)
338                                         break;
339
340                                 res = dhcpv6_request(DHCPV6_MSG_INFO_REQ);
341                                 odhcp6c_signal_process();
342                                 if (signal_usr1)
343                                         continue;
344                                 else if (res < 0)
345                                         break;
346                         }
347                         break;
348
349                 case DHCPV6_STATEFUL:
350                         script_call("bound");
351                         bound = true;
352                         syslog(LOG_NOTICE, "entering stateful-mode on %s", ifname);
353 #ifdef EXT_BFD_PING
354                         if (bfd_interval > 0)
355                                 bfd_start(ifname, bfd_loss, bfd_interval);
356 #endif
357
358                         while (!signal_usr2 && !signal_term) {
359                                 // Renew Cycle
360                                 // Wait for T1 to expire or until we get a reconfigure
361                                 int res = dhcpv6_poll_reconfigure();
362                                 odhcp6c_signal_process();
363                                 if (res > 0) {
364                                         script_call("updated");
365                                         continue;
366                                 }
367
368                                 // Handle signal, if necessary
369                                 if (signal_usr1)
370                                         signal_usr1 = false; // Acknowledged
371                                 if (signal_usr2 || signal_term)
372                                         break; // Other signal type
373
374                                 // Send renew as T1 expired
375                                 size_t ia_pd_len, ia_na_len;
376                                 odhcp6c_get_state(STATE_IA_PD, &ia_pd_len);
377                                 odhcp6c_get_state(STATE_IA_NA, &ia_na_len);
378
379                                 // If we have any IAs, send renew, otherwise request
380                                 if (ia_pd_len == 0 && ia_na_len == 0)
381                                         res = dhcpv6_request(DHCPV6_MSG_REQUEST);
382                                 else
383                                         res = dhcpv6_request(DHCPV6_MSG_RENEW);
384
385                                 odhcp6c_signal_process();
386                                 if (res > 0) { // Renew was succesfull
387                                         // Publish updates
388                                         script_call("updated");
389                                         continue; // Renew was successful
390                                 }
391
392                                 odhcp6c_clear_state(STATE_SERVER_ID); // Remove binding
393
394                                 odhcp6c_get_state(STATE_IA_PD, &ia_pd_len);
395                                 odhcp6c_get_state(STATE_IA_NA, &ia_na_len);
396
397                                 if (ia_pd_len == 0 && ia_na_len == 0)
398                                         break;
399
400                                 // If we have IAs, try rebind otherwise restart
401                                 res = dhcpv6_request(DHCPV6_MSG_REBIND);
402                                 odhcp6c_signal_process();
403
404                                 if (res > 0)
405                                         script_call("rebound");
406                                 else {
407 #ifdef EXT_BFD_PING
408                                         bfd_stop();
409 #endif
410                                         break;
411                                 }
412                         }
413                         break;
414
415                 default:
416                         break;
417                 }
418
419                 size_t ia_pd_len, ia_na_len, server_id_len;
420                 odhcp6c_get_state(STATE_IA_PD, &ia_pd_len);
421                 odhcp6c_get_state(STATE_IA_NA, &ia_na_len);
422                 odhcp6c_get_state(STATE_SERVER_ID, &server_id_len);
423
424                 // Add all prefixes to lost prefixes
425                 bound = false;
426                 script_call("unbound");
427
428                 if (server_id_len > 0 && (ia_pd_len > 0 || ia_na_len > 0) && release)
429                         dhcpv6_request(DHCPV6_MSG_RELEASE);
430
431                 odhcp6c_clear_state(STATE_IA_NA);
432                 odhcp6c_clear_state(STATE_IA_PD);
433         }
434
435         script_call("stopped");
436         return 0;
437 }
438
439
440 static int usage(void)
441 {
442         const char buf[] =
443         "Usage: odhcp6c [options] <interface>\n"
444         "\nFeature options:\n"
445         "       -S <time>       Wait at least <time> sec for a DHCP-server (0)\n"
446         "       -N <mode>       Mode for requesting addresses [try|force|none]\n"
447         "       -P <length>     Request IPv6-Prefix (0 = auto)\n"
448         "       -F              Force IPv6-Prefix\n"
449         "       -V <class>      Set vendor-class option (base-16 encoded)\n"
450 #ifdef EXT_BFD_PING
451         "       -B <interval>   Enable BFD ping check\n"
452 #endif
453         "       -u <user-class> Set user-class option string\n"
454         "       -c <clientid>   Override client-ID (base-16 encoded)\n"
455         "       -i <iface-id>   Use a custom interface identifier for RA handling\n"
456         "       -r <options>    Options to be requested (comma-separated)\n"
457         "       -R              Do not request any options except those specified with -r\n"
458         "       -s <script>     Status update script (/usr/sbin/odhcp6c-update)\n"
459         "       -a              Don't send Accept Reconfigure option\n"
460         "       -f              Don't send Client FQDN option\n"
461         "       -k              Don't send a RELEASE when stopping\n"
462         "       -t <seconds>    Maximum timeout for DHCPv6-SOLICIT (3600)\n"
463         "       -m <seconds>    Minimum time between accepting updates (30)\n"
464         "\nInvocation options:\n"
465         "       -p <pidfile>    Set pidfile (/var/run/odhcp6c.pid)\n"
466         "       -d              Daemonize\n"
467         "       -e              Write logmessages to stderr\n"
468         //"     -v              Increase logging verbosity\n"
469         "       -h              Show this help\n\n";
470         write(STDERR_FILENO, buf, sizeof(buf));
471         return 1;
472 }
473
474
475 // Don't want to pull-in librt and libpthread just for a monotonic clock...
476 uint64_t odhcp6c_get_milli_time(void)
477 {
478         struct timespec t = {0, 0};
479         syscall(SYS_clock_gettime, CLOCK_MONOTONIC, &t);
480         return ((uint64_t)t.tv_sec) * 1000 + ((uint64_t)t.tv_nsec) / 1000000;
481 }
482
483
484 static uint8_t* odhcp6c_resize_state(enum odhcp6c_state state, ssize_t len)
485 {
486         if (len == 0)
487                 return state_data[state] + state_len[state];
488         else if (state_len[state] + len > 1024)
489                 return NULL;
490
491         uint8_t *n = realloc(state_data[state], state_len[state] + len);
492         if (n || state_len[state] + len == 0) {
493                 state_data[state] = n;
494                 n += state_len[state];
495                 state_len[state] += len;
496         }
497         return n;
498 }
499
500
501 bool odhcp6c_signal_process(void)
502 {
503         while (signal_io) {
504                 signal_io = false;
505
506                 bool ra_updated = ra_process();
507
508                 if (ra_link_up())
509                         signal_usr2 = true;
510
511                 if (ra_updated && (bound || allow_slaac_only == 0))
512                         script_call("ra-updated"); // Immediate process urgent events
513                 else if (ra_updated && !bound && allow_slaac_only > 0)
514                         script_delay_call("ra-updated", allow_slaac_only);
515
516 #ifdef EXT_BFD_PING
517                 bfd_receive();
518 #endif
519         }
520
521         return signal_usr1 || signal_usr2 || signal_term;
522 }
523
524
525 void odhcp6c_clear_state(enum odhcp6c_state state)
526 {
527         state_len[state] = 0;
528 }
529
530
531 void odhcp6c_add_state(enum odhcp6c_state state, const void *data, size_t len)
532 {
533         uint8_t *n = odhcp6c_resize_state(state, len);
534         if (n)
535                 memcpy(n, data, len);
536 }
537
538 void odhcp6c_insert_state(enum odhcp6c_state state, size_t offset, const void *data, size_t len)
539 {
540         ssize_t len_after = state_len[state] - offset;
541         if (len_after < 0)
542                 return;
543
544         uint8_t *n = odhcp6c_resize_state(state, len);
545         if (n) {
546                 uint8_t *sdata = state_data[state];
547
548                 memmove(sdata + offset + len, sdata + offset, len_after);
549                 memcpy(sdata + offset, data, len);
550         }
551 }
552
553 size_t odhcp6c_remove_state(enum odhcp6c_state state, size_t offset, size_t len)
554 {
555         uint8_t *data = state_data[state];
556         ssize_t len_after = state_len[state] - (offset + len);
557         if (len_after < 0)
558                 return state_len[state];
559
560         memmove(data + offset, data + offset + len, len_after);
561         return state_len[state] -= len;
562 }
563
564
565 void* odhcp6c_move_state(enum odhcp6c_state state, size_t *len)
566 {
567         *len = state_len[state];
568         void *data = state_data[state];
569
570         state_len[state] = 0;
571         state_data[state] = NULL;
572
573         return data;
574 }
575
576
577 void* odhcp6c_get_state(enum odhcp6c_state state, size_t *len)
578 {
579         *len = state_len[state];
580         return state_data[state];
581 }
582
583
584 struct odhcp6c_entry* odhcp6c_find_entry(enum odhcp6c_state state, const struct odhcp6c_entry *new)
585 {
586         size_t len, cmplen = offsetof(struct odhcp6c_entry, target) + new->length / 8;
587         struct odhcp6c_entry *start = odhcp6c_get_state(state, &len);
588         struct odhcp6c_entry *x = NULL;
589
590         for (struct odhcp6c_entry *c = start; !x && c < &start[len/sizeof(*c)]; ++c)
591                 if (!memcmp(c, new, cmplen))
592                         return c;
593
594         return NULL;
595 }
596
597
598 bool odhcp6c_update_entry_safe(enum odhcp6c_state state, struct odhcp6c_entry *new, uint32_t safe)
599 {
600         size_t len;
601         struct odhcp6c_entry *x = odhcp6c_find_entry(state, new);
602         struct odhcp6c_entry *start = odhcp6c_get_state(state, &len);
603
604         if (x && x->valid > new->valid && new->valid < safe)
605                 new->valid = safe;
606
607         if (new->valid > 0) {
608                 if (x) {
609                         if (new->valid >= x->valid && new->valid != UINT32_MAX &&
610                                         new->valid - x->valid < min_update_interval &&
611                                         new->preferred >= x->preferred &&
612                                         new->preferred != UINT32_MAX &&
613                                         new->preferred - x->preferred < min_update_interval &&
614                                         x->class == new->class)
615                                 return false;
616                         x->valid = new->valid;
617                         x->preferred = new->preferred;
618                         x->t1 = new->t1;
619                         x->t2 = new->t2;
620                         x->class = new->class;
621                         x->iaid = new->iaid;
622                 } else {
623                         odhcp6c_add_state(state, new, sizeof(*new));
624                 }
625         } else if (x) {
626                 odhcp6c_remove_state(state, (x - start) * sizeof(*x), sizeof(*x));
627         }
628         return true;
629 }
630
631
632 bool odhcp6c_update_entry(enum odhcp6c_state state, struct odhcp6c_entry *new)
633 {
634         return odhcp6c_update_entry_safe(state, new, 0);
635 }
636
637
638 static void odhcp6c_expire_list(enum odhcp6c_state state, uint32_t elapsed)
639 {
640         size_t len;
641         struct odhcp6c_entry *start = odhcp6c_get_state(state, &len);
642         for (struct odhcp6c_entry *c = start; c < &start[len / sizeof(*c)]; ++c) {
643                 if (c->t1 < elapsed)
644                         c->t1 = 0;
645                 else if (c->t1 != UINT32_MAX)
646                         c->t1 -= elapsed;
647
648                 if (c->t2 < elapsed)
649                         c->t2 = 0;
650                 else if (c->t2 != UINT32_MAX)
651                         c->t2 -= elapsed;
652
653                 if (c->preferred < elapsed)
654                         c->preferred = 0;
655                 else if (c->preferred != UINT32_MAX)
656                         c->preferred -= elapsed;
657
658                 if (c->valid < elapsed)
659                         c->valid = 0;
660                 else if (c->valid != UINT32_MAX)
661                         c->valid -= elapsed;
662
663                 if (!c->valid)
664                         odhcp6c_remove_state(state, (c - start) * sizeof(*c), sizeof(*c));
665         }
666 }
667
668
669 void odhcp6c_expire(void)
670 {
671         time_t now = odhcp6c_get_milli_time() / 1000;
672         uint32_t elapsed = (last_update > 0) ? now - last_update : 0;
673         last_update = now;
674
675         odhcp6c_expire_list(STATE_RA_PREFIX, elapsed);
676         odhcp6c_expire_list(STATE_RA_ROUTE, elapsed);
677         odhcp6c_expire_list(STATE_RA_DNS, elapsed);
678         odhcp6c_expire_list(STATE_IA_NA, elapsed);
679         odhcp6c_expire_list(STATE_IA_PD, elapsed);
680 }
681
682
683 uint32_t odhcp6c_elapsed(void)
684 {
685         return odhcp6c_get_milli_time() / 1000 - last_update;
686 }
687
688
689 void odhcp6c_random(void *buf, size_t len)
690 {
691         read(urandom_fd, buf, len);
692 }
693
694 bool odhcp6c_is_bound(void)
695 {
696         return bound;
697 }
698
699 static void sighandler(int signal)
700 {
701         if (signal == SIGCHLD)
702                 while (waitpid(-1, NULL, WNOHANG) > 0);
703         else if (signal == SIGUSR1)
704                 signal_usr1 = true;
705         else if (signal == SIGUSR2)
706                 signal_usr2 = true;
707         else if (signal == SIGIO)
708                 signal_io = true;
709         else
710                 signal_term = true;
711 }