e280142f7562edc6038a1b2b725e54f72c3cb5ce
[openwrt/staging/blogic.git] / package / network / services / dnsmasq / patches / 260-dnssec-SIGINT.patch
1 From 3c973ad92d317df736d5a8fde67baba6b102d91e Mon Sep 17 00:00:00 2001
2 From: Simon Kelley <simon@thekelleys.org.uk>
3 Date: Sun, 14 Jan 2018 21:05:37 +0000
4 Subject: [PATCH] Use SIGINT (instead of overloading SIGHUP) to turn on DNSSEC
5 time validation.
6
7 ---
8 src/dnsmasq.c | 36 +++++++++++++++++++++++++-----------
9 src/dnsmasq.h | 1 +
10 src/helper.c | 3 ++-
11 5 files changed, 38 insertions(+), 14 deletions(-)
12
13 --- a/src/dnsmasq.c
14 +++ b/src/dnsmasq.c
15 @@ -137,7 +137,8 @@ int main (int argc, char **argv)
16 sigaction(SIGTERM, &sigact, NULL);
17 sigaction(SIGALRM, &sigact, NULL);
18 sigaction(SIGCHLD, &sigact, NULL);
19 -
20 + sigaction(SIGINT, &sigact, NULL);
21 +
22 /* ignore SIGPIPE */
23 sigact.sa_handler = SIG_IGN;
24 sigaction(SIGPIPE, &sigact, NULL);
25 @@ -815,7 +816,7 @@ int main (int argc, char **argv)
26
27 daemon->dnssec_no_time_check = option_bool(OPT_DNSSEC_TIME);
28 if (option_bool(OPT_DNSSEC_TIME) && !daemon->back_to_the_future)
29 - my_syslog(LOG_INFO, _("DNSSEC signature timestamps not checked until first cache reload"));
30 + my_syslog(LOG_INFO, _("DNSSEC signature timestamps not checked until receipt of SIGINT"));
31
32 if (rc == 1)
33 my_syslog(LOG_INFO, _("DNSSEC signature timestamps not checked until system time valid"));
34 @@ -1142,7 +1143,7 @@ static void sig_handler(int sig)
35 {
36 /* ignore anything other than TERM during startup
37 and in helper proc. (helper ignore TERM too) */
38 - if (sig == SIGTERM)
39 + if (sig == SIGTERM || sig == SIGINT)
40 exit(EC_MISC);
41 }
42 else if (pid != getpid())
43 @@ -1168,6 +1169,15 @@ static void sig_handler(int sig)
44 event = EVENT_DUMP;
45 else if (sig == SIGUSR2)
46 event = EVENT_REOPEN;
47 + else if (sig == SIGINT)
48 + {
49 + /* Handle SIGINT normally in debug mode, so
50 + ctrl-c continues to operate. */
51 + if (option_bool(OPT_DEBUG))
52 + exit(EC_MISC);
53 + else
54 + event = EVENT_TIME;
55 + }
56 else
57 return;
58
59 @@ -1295,14 +1305,7 @@ static void async_event(int pipe, time_t
60 {
61 case EVENT_RELOAD:
62 daemon->soa_sn++; /* Bump zone serial, as it may have changed. */
63 -
64 -#ifdef HAVE_DNSSEC
65 - if (daemon->dnssec_no_time_check && option_bool(OPT_DNSSEC_VALID) && option_bool(OPT_DNSSEC_TIME))
66 - {
67 - my_syslog(LOG_INFO, _("now checking DNSSEC signature timestamps"));
68 - daemon->dnssec_no_time_check = 0;
69 - }
70 -#endif
71 +
72 /* fall through */
73
74 case EVENT_INIT:
75 @@ -1411,6 +1414,17 @@ static void async_event(int pipe, time_t
76 poll_resolv(0, 1, now);
77 break;
78
79 + case EVENT_TIME:
80 +#ifdef HAVE_DNSSEC
81 + if (daemon->dnssec_no_time_check && option_bool(OPT_DNSSEC_VALID) && option_bool(OPT_DNSSEC_TIME))
82 + {
83 + my_syslog(LOG_INFO, _("now checking DNSSEC signature timestamps"));
84 + daemon->dnssec_no_time_check = 0;
85 + clear_cache_and_reload(now);
86 + }
87 +#endif
88 + break;
89 +
90 case EVENT_TERM:
91 /* Knock all our children on the head. */
92 for (i = 0; i < MAX_PROCS; i++)
93 --- a/src/dnsmasq.h
94 +++ b/src/dnsmasq.h
95 @@ -175,6 +175,7 @@ struct event_desc {
96 #define EVENT_NEWROUTE 23
97 #define EVENT_TIME_ERR 24
98 #define EVENT_SCRIPT_LOG 25
99 +#define EVENT_TIME 26
100
101 /* Exit codes. */
102 #define EC_GOOD 0
103 --- a/src/helper.c
104 +++ b/src/helper.c
105 @@ -97,13 +97,14 @@ int create_helper(int event_fd, int err_
106 return pipefd[1];
107 }
108
109 - /* ignore SIGTERM, so that we can clean up when the main process gets hit
110 + /* ignore SIGTERM and SIGINT, so that we can clean up when the main process gets hit
111 and SIGALRM so that we can use sleep() */
112 sigact.sa_handler = SIG_IGN;
113 sigact.sa_flags = 0;
114 sigemptyset(&sigact.sa_mask);
115 sigaction(SIGTERM, &sigact, NULL);
116 sigaction(SIGALRM, &sigact, NULL);
117 + sigaction(SIGINT, &sigact, NULL);
118
119 if (!option_bool(OPT_DEBUG) && uid != 0)
120 {