78f31d0c2d38f7de5c08e01d4c5359d3c6fbdd74
[openwrt/staging/hauke.git] /
1 From 48d12f14c9c0fc8cf943b52774c3892517dd72d4 Mon Sep 17 00:00:00 2001
2 From: Simon Kelley <simon@thekelleys.org.uk>
3 Date: Fri, 2 Nov 2018 21:55:04 +0000
4 Subject: [PATCH 10/32] Remove the NO_FORK compile-time option, and support for
5 uclinux.
6
7 In an era where everything has an MMU, this looks like
8 an anachronism, and it adds to (Ok, multiplies!) the
9 combinatorial explosion of compile-time options.
10
11 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
12 ---
13 CHANGELOG | 6 ++++++
14 src/config.h | 21 ++-------------------
15 src/dnsmasq.c | 14 --------------
16 src/option.c | 4 +---
17 4 files changed, 9 insertions(+), 36 deletions(-)
18
19 --- a/CHANGELOG
20 +++ b/CHANGELOG
21 @@ -11,6 +11,12 @@ version 2.81
22 This fix passes cache entries back from the TCP child process to
23 the main server process, and fixes the problem.
24
25 + Remove the NO_FORK compile-time option, and support for uclinux.
26 + In an era where everything has an MMU, this looks like
27 + an anachronism, and it adds to (Ok, multiplies!) the
28 + combinatorial explosion of compile-time options. Thanks to
29 + Kevin Darbyshire-Bryant for the patch.
30 +
31
32 version 2.80
33 Add support for RFC 4039 DHCP rapid commit. Thanks to Ashram Method
34 --- a/src/config.h
35 +++ b/src/config.h
36 @@ -239,27 +239,13 @@ HAVE_SOCKADDR_SA_LEN
37 defined if struct sockaddr has sa_len field (*BSD)
38 */
39
40 -/* Must precede __linux__ since uClinux defines __linux__ too. */
41 -#if defined(__uClinux__)
42 -#define HAVE_LINUX_NETWORK
43 -#define HAVE_GETOPT_LONG
44 -#undef HAVE_SOCKADDR_SA_LEN
45 -/* Never use fork() on uClinux. Note that this is subtly different from the
46 - --keep-in-foreground option, since it also suppresses forking new
47 - processes for TCP connections and disables the call-a-script on leasechange
48 - system. It's intended for use on MMU-less kernels. */
49 -#define NO_FORK
50 -
51 -#elif defined(__UCLIBC__)
52 +#if defined(__UCLIBC__)
53 #define HAVE_LINUX_NETWORK
54 #if defined(__UCLIBC_HAS_GNU_GETOPT__) || \
55 ((__UCLIBC_MAJOR__==0) && (__UCLIBC_MINOR__==9) && (__UCLIBC_SUBLEVEL__<21))
56 # define HAVE_GETOPT_LONG
57 #endif
58 #undef HAVE_SOCKADDR_SA_LEN
59 -#if !defined(__ARCH_HAS_MMU__) && !defined(__UCLIBC_HAS_MMU__)
60 -# define NO_FORK
61 -#endif
62 #if defined(__UCLIBC_HAS_IPV6__)
63 # ifndef IPV6_V6ONLY
64 # define IPV6_V6ONLY 26
65 @@ -328,7 +314,7 @@ HAVE_SOCKADDR_SA_LEN
66 #define HAVE_DHCP
67 #endif
68
69 -#if defined(NO_SCRIPT) || defined(NO_FORK)
70 +#if defined(NO_SCRIPT)
71 #undef HAVE_SCRIPT
72 #undef HAVE_LUASCRIPT
73 #endif
74 @@ -372,9 +358,6 @@ static char *compile_opts =
75 #ifdef HAVE_BROKEN_RTC
76 "no-RTC "
77 #endif
78 -#ifdef NO_FORK
79 -"no-MMU "
80 -#endif
81 #ifndef HAVE_DBUS
82 "no-"
83 #endif
84 --- a/src/dnsmasq.c
85 +++ b/src/dnsmasq.c
86 @@ -485,7 +485,6 @@ int main (int argc, char **argv)
87 if (chdir("/") != 0)
88 die(_("cannot chdir to filesystem root: %s"), NULL, EC_MISC);
89
90 -#ifndef NO_FORK
91 if (!option_bool(OPT_NO_FORK))
92 {
93 pid_t pid;
94 @@ -525,7 +524,6 @@ int main (int argc, char **argv)
95 if (pid != 0)
96 _exit(0);
97 }
98 -#endif
99
100 /* write pidfile _after_ forking ! */
101 if (daemon->runfile)
102 @@ -1628,12 +1626,10 @@ static int set_dns_listeners(time_t now)
103
104 }
105
106 -#ifndef NO_FORK
107 if (!option_bool(OPT_DEBUG))
108 for (i = 0; i < MAX_PROCS; i++)
109 if (daemon->tcp_pipes[i] != -1)
110 poll_listen(daemon->tcp_pipes[i], POLLIN);
111 -#endif
112
113 return wait;
114 }
115 @@ -1643,9 +1639,7 @@ static void check_dns_listeners(time_t n
116 struct serverfd *serverfdp;
117 struct listener *listener;
118 int i;
119 -#ifndef NO_FORK
120 int pipefd[2];
121 -#endif
122
123 for (serverfdp = daemon->sfds; serverfdp; serverfdp = serverfdp->next)
124 if (poll_check(serverfdp->fd, POLLIN))
125 @@ -1657,7 +1651,6 @@ static void check_dns_listeners(time_t n
126 poll_check(daemon->randomsocks[i].fd, POLLIN))
127 reply_query(daemon->randomsocks[i].fd, daemon->randomsocks[i].family, now);
128
129 -#ifndef NO_FORK
130 /* Races. The child process can die before we read all of the data from the
131 pipe, or vice versa. Therefore send tcp_pids to zero when we wait() the
132 process, and tcp_pipes to -1 and close the FD when we read the last
133 @@ -1674,7 +1667,6 @@ static void check_dns_listeners(time_t n
134 close(daemon->tcp_pipes[i]);
135 daemon->tcp_pipes[i] = -1;
136 }
137 -#endif
138
139 for (listener = daemon->listeners; listener; listener = listener->next)
140 {
141 @@ -1768,7 +1760,6 @@ static void check_dns_listeners(time_t n
142 shutdown(confd, SHUT_RDWR);
143 while (retry_send(close(confd)));
144 }
145 -#ifndef NO_FORK
146 else if (!option_bool(OPT_DEBUG) && pipe(pipefd) == 0 && (p = fork()) != 0)
147 {
148 close(pipefd[1]); /* parent needs read pipe end. */
149 @@ -1791,7 +1782,6 @@ static void check_dns_listeners(time_t n
150 /* The child can use up to TCP_MAX_QUERIES ids, so skip that many. */
151 daemon->log_id += TCP_MAX_QUERIES;
152 }
153 -#endif
154 else
155 {
156 unsigned char *buff;
157 @@ -1811,7 +1801,6 @@ static void check_dns_listeners(time_t n
158 auth_dns = 0;
159 }
160
161 -#ifndef NO_FORK
162 /* Arrange for SIGALRM after CHILD_LIFETIME seconds to
163 terminate the process. */
164 if (!option_bool(OPT_DEBUG))
165 @@ -1820,7 +1809,6 @@ static void check_dns_listeners(time_t n
166 close(pipefd[0]); /* close read end in child. */
167 daemon->pipe_to_parent = pipefd[1];
168 }
169 -#endif
170
171 /* start with no upstream connections. */
172 for (s = daemon->servers; s; s = s->next)
173 @@ -1846,13 +1834,11 @@ static void check_dns_listeners(time_t n
174 shutdown(s->tcpfd, SHUT_RDWR);
175 while (retry_send(close(s->tcpfd)));
176 }
177 -#ifndef NO_FORK
178 if (!option_bool(OPT_DEBUG))
179 {
180 flush_log();
181 _exit(0);
182 }
183 -#endif
184 }
185 }
186 }
187 --- a/src/option.c
188 +++ b/src/option.c
189 @@ -1828,9 +1828,7 @@ static int one_opt(int option, char *arg
190 /* Sorry about the gross pre-processor abuse */
191 case '6': /* --dhcp-script */
192 case LOPT_LUASCRIPT: /* --dhcp-luascript */
193 -# if defined(NO_FORK)
194 - ret_err(_("cannot run scripts under uClinux"));
195 -# elif !defined(HAVE_SCRIPT)
196 +# if !defined(HAVE_SCRIPT)
197 ret_err(_("recompile with HAVE_SCRIPT defined to enable lease-change scripts"));
198 # else
199 if (option == LOPT_LUASCRIPT)