2 3e4749f7 2020-10-02 op * Copyright (c) 2020 Omar Polo <op@omarpolo.com>
4 3e4749f7 2020-10-02 op * Permission to use, copy, modify, and distribute this software for any
5 3e4749f7 2020-10-02 op * purpose with or without fee is hereby granted, provided that the above
6 3e4749f7 2020-10-02 op * copyright notice and this permission notice appear in all copies.
8 3e4749f7 2020-10-02 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 3e4749f7 2020-10-02 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 3e4749f7 2020-10-02 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 3e4749f7 2020-10-02 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 3e4749f7 2020-10-02 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 3e4749f7 2020-10-02 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 3e4749f7 2020-10-02 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 52418c8d 2021-02-12 op #include "gmid.h"
19 8443bff7 2021-01-25 op #include <sys/stat.h>
21 592fd624 2020-10-07 op #include <errno.h>
22 3e4749f7 2020-10-02 op #include <fcntl.h>
23 7e1df73d 2021-03-31 op #include <libgen.h>
24 bcf5d929 2021-02-01 op #include <limits.h>
25 ae08ec7d 2021-01-25 op #include <pwd.h>
26 0cf902af 2020-11-03 op #include <signal.h>
27 3e4749f7 2020-10-02 op #include <string.h>
29 b8e64ccd 2021-03-31 op struct vhosthead hosts;
31 bc99d868 2021-03-19 op int sock4, sock6;
33 bc99d868 2021-03-19 op struct imsgbuf logibuf, exibuf, servibuf[PROC_MAX];
35 d672b8fb 2021-02-03 op const char *config_path, *certs_dir, *hostname;
37 15902770 2021-01-15 op struct conf conf;
39 ca21e100 2021-02-04 op struct tls_config *tlsconf;
40 ae08ec7d 2021-01-25 op struct tls *ctx;
43 b9c9123b 2021-03-20 op dummy_handler(int signo)
48 7e1df73d 2021-03-31 op /* wrapper around dirname(3). dn must be PATH_MAX+1 at least. */
50 7e1df73d 2021-03-31 op pdirname(const char *path, char *dn)
52 7e1df73d 2021-03-31 op char p[PATH_MAX+1];
55 7e1df73d 2021-03-31 op strlcpy(p, path, sizeof(p));
56 7e1df73d 2021-03-31 op t = dirname(p);
57 7e1df73d 2021-03-31 op memmove(dn, t, strlen(t)+1);
61 7e1df73d 2021-03-31 op mkdirs(const char *path, mode_t mode)
63 7e1df73d 2021-03-31 op char dname[PATH_MAX+1];
65 7e1df73d 2021-03-31 op pdirname(path, dname);
66 7e1df73d 2021-03-31 op if (!strcmp(dname, "/"))
68 7e1df73d 2021-03-31 op mkdirs(dname, mode);
69 7e1df73d 2021-03-31 op if (mkdir(path, mode) != 0 && errno != EEXIST)
70 8443bff7 2021-01-25 op fatal("can't mkdir %s: %s", path, strerror(errno));
73 8443bff7 2021-01-25 op /* $XDG_DATA_HOME/gmid */
75 8443bff7 2021-01-25 op data_dir(void)
77 8443bff7 2021-01-25 op const char *home, *xdg;
80 8443bff7 2021-01-25 op if ((xdg = getenv("XDG_DATA_HOME")) == NULL) {
81 8443bff7 2021-01-25 op if ((home = getenv("HOME")) == NULL)
82 8443bff7 2021-01-25 op errx(1, "XDG_DATA_HOME and HOME both empty");
83 8443bff7 2021-01-25 op if (asprintf(&t, "%s/.local/share/gmid", home) == -1)
84 8443bff7 2021-01-25 op err(1, "asprintf");
86 7e1df73d 2021-03-31 op if (asprintf(&t, "%s/gmid", xdg) == -1)
87 7e1df73d 2021-03-31 op err(1, "asprintf");
90 7e1df73d 2021-03-31 op mkdirs(t, 0755);
95 8443bff7 2021-01-25 op load_local_cert(const char *hostname, const char *dir)
97 8443bff7 2021-01-25 op char *cert, *key;
98 b8e64ccd 2021-03-31 op struct vhost *h;
100 8443bff7 2021-01-25 op if (asprintf(&cert, "%s/%s.cert.pem", dir, hostname) == -1)
101 8443bff7 2021-01-25 op errx(1, "asprintf");
102 8443bff7 2021-01-25 op if (asprintf(&key, "%s/%s.key.pem", dir, hostname) == -1)
103 8443bff7 2021-01-25 op errx(1, "asprintf");
105 8443bff7 2021-01-25 op if (access(cert, R_OK) == -1 || access(key, R_OK) == -1)
106 8443bff7 2021-01-25 op gen_certificate(hostname, cert, key);
108 b8e64ccd 2021-03-31 op h = TAILQ_FIRST(&hosts);
109 b8e64ccd 2021-03-31 op h->cert = cert;
110 b8e64ccd 2021-03-31 op h->key = key;
111 b8e64ccd 2021-03-31 op h->domain = hostname;
115 ae08ec7d 2021-01-25 op load_vhosts(void)
117 15902770 2021-01-15 op struct vhost *h;
119 b8e64ccd 2021-03-31 op TAILQ_FOREACH(h, &hosts, vhosts) {
120 d3a08f4d 2021-01-17 op if ((h->dirfd = open(h->dir, O_RDONLY | O_DIRECTORY)) == -1)
121 132cae8c 2021-01-18 op fatal("open %s for domain %s", h->dir, h->domain);
126 9468027b 2020-10-15 op make_socket(int port, int family)
129 9468027b 2020-10-15 op struct sockaddr_in addr4;
130 9468027b 2020-10-15 op struct sockaddr_in6 addr6;
131 9468027b 2020-10-15 op struct sockaddr *addr;
132 9468027b 2020-10-15 op socklen_t len;
134 9468027b 2020-10-15 op switch (family) {
135 9468027b 2020-10-15 op case AF_INET:
136 9468027b 2020-10-15 op bzero(&addr4, sizeof(addr4));
137 9468027b 2020-10-15 op addr4.sin_family = family;
138 9468027b 2020-10-15 op addr4.sin_port = htons(port);
139 9468027b 2020-10-15 op addr4.sin_addr.s_addr = INADDR_ANY;
140 9468027b 2020-10-15 op addr = (struct sockaddr*)&addr4;
141 9468027b 2020-10-15 op len = sizeof(addr4);
144 9468027b 2020-10-15 op case AF_INET6:
145 9468027b 2020-10-15 op bzero(&addr6, sizeof(addr6));
146 9468027b 2020-10-15 op addr6.sin6_family = AF_INET6;
147 9468027b 2020-10-15 op addr6.sin6_port = htons(port);
148 9468027b 2020-10-15 op addr6.sin6_addr = in6addr_any;
149 9468027b 2020-10-15 op addr = (struct sockaddr*)&addr6;
150 9468027b 2020-10-15 op len = sizeof(addr6);
154 9468027b 2020-10-15 op /* unreachable */
158 9468027b 2020-10-15 op if ((sock = socket(family, SOCK_STREAM, 0)) == -1)
159 80bbcad5 2021-01-10 op fatal("socket: %s", strerror(errno));
162 3e4749f7 2020-10-02 op if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v)) == -1)
163 80bbcad5 2021-01-10 op fatal("setsockopt(SO_REUSEADDR): %s", strerror(errno));
166 3e4749f7 2020-10-02 op if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &v, sizeof(v)) == -1)
167 80bbcad5 2021-01-10 op fatal("setsockopt(SO_REUSEPORT): %s", strerror(errno));
169 592fd624 2020-10-07 op mark_nonblock(sock);
171 9468027b 2020-10-15 op if (bind(sock, addr, len) == -1)
172 80bbcad5 2021-01-10 op fatal("bind: %s", strerror(errno));
174 3e4749f7 2020-10-02 op if (listen(sock, 16) == -1)
175 80bbcad5 2021-01-10 op fatal("listen: %s", strerror(errno));
181 ae08ec7d 2021-01-25 op setup_tls(void)
183 ae08ec7d 2021-01-25 op struct vhost *h;
185 881a9dd9 2021-01-16 op if ((tlsconf = tls_config_new()) == NULL)
186 132cae8c 2021-01-18 op fatal("tls_config_new");
188 881a9dd9 2021-01-16 op /* optionally accept client certs, but don't try to verify them */
189 881a9dd9 2021-01-16 op tls_config_verify_client_optional(tlsconf);
190 881a9dd9 2021-01-16 op tls_config_insecure_noverifycert(tlsconf);
192 881a9dd9 2021-01-16 op if (tls_config_set_protocols(tlsconf, conf.protos) == -1)
193 132cae8c 2021-01-18 op fatal("tls_config_set_protocols");
195 881a9dd9 2021-01-16 op if ((ctx = tls_server()) == NULL)
196 132cae8c 2021-01-18 op fatal("tls_server failure");
198 b8e64ccd 2021-03-31 op h = TAILQ_FIRST(&hosts);
200 ae08ec7d 2021-01-25 op /* we need to set something, then we can add how many key we want */
201 b8e64ccd 2021-03-31 op if (tls_config_set_keypair_file(tlsconf, h->cert, h->key))
202 ca21e100 2021-02-04 op fatal("tls_config_set_keypair_file failed for (%s, %s)",
203 b8e64ccd 2021-03-31 op h->cert, h->key);
205 b8e64ccd 2021-03-31 op while ((h = TAILQ_NEXT(h, vhosts)) != NULL) {
206 ae08ec7d 2021-01-25 op if (tls_config_add_keypair_file(tlsconf, h->cert, h->key) == -1)
207 ae08ec7d 2021-01-25 op fatal("failed to load the keypair (%s, %s)",
208 ae08ec7d 2021-01-25 op h->cert, h->key);
211 881a9dd9 2021-01-16 op if (tls_configure(ctx, tlsconf) == -1)
212 132cae8c 2021-01-18 op fatal("tls_configure: %s", tls_error(ctx));
216 bc99d868 2021-03-19 op listener_main(struct imsgbuf *ibuf)
219 ae08ec7d 2021-01-25 op load_default_mime(&conf.mime);
220 ae08ec7d 2021-01-25 op load_vhosts();
221 bc99d868 2021-03-19 op loop(ctx, sock4, sock6, ibuf);
226 8d6ae384 2021-01-24 op init_config(void)
228 b8e64ccd 2021-03-31 op TAILQ_INIT(&hosts);
230 15902770 2021-01-15 op conf.port = 1965;
231 15902770 2021-01-15 op conf.ipv6 = 0;
232 5bc3c98e 2021-01-15 op conf.protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3;
234 b2a6b613 2021-01-21 op init_mime(&conf.mime);
236 ae08ec7d 2021-01-25 op conf.chroot = NULL;
237 ae08ec7d 2021-01-25 op conf.user = NULL;
239 a709ddf5 2021-02-07 op conf.prefork = 3;
243 ca21e100 2021-02-04 op free_config(void)
245 b8e64ccd 2021-03-31 op struct vhost *h, *th;
246 b8e64ccd 2021-03-31 op struct location *l, *tl;
248 ca21e100 2021-02-04 op free(conf.chroot);
249 ca21e100 2021-02-04 op free(conf.user);
250 ca21e100 2021-02-04 op memset(&conf, 0, sizeof(conf));
252 b8e64ccd 2021-03-31 op TAILQ_FOREACH_SAFE(h, &hosts, vhosts, th) {
253 b8e64ccd 2021-03-31 op TAILQ_FOREACH_SAFE(l, &h->locations, locations, tl) {
254 b8e64ccd 2021-03-31 op TAILQ_REMOVE(&h->locations, l, locations);
256 ca21e100 2021-02-04 op free((char*)l->match);
257 ca21e100 2021-02-04 op free((char*)l->lang);
258 ca21e100 2021-02-04 op free((char*)l->default_mime);
259 ca21e100 2021-02-04 op free((char*)l->index);
260 6abda252 2021-02-06 op free((char*)l->block_fmt);
264 b8e64ccd 2021-03-31 op TAILQ_REMOVE(&hosts, h, vhosts);
268 ca21e100 2021-02-04 op tls_free(ctx);
269 ca21e100 2021-02-04 op tls_config_free(tlsconf);
273 1d3eb470 2021-03-20 op wait_signal(void)
275 ca21e100 2021-02-04 op sigset_t mask;
278 ca21e100 2021-02-04 op sigemptyset(&mask);
279 ca21e100 2021-02-04 op sigaddset(&mask, SIGHUP);
280 1d3eb470 2021-03-20 op sigaddset(&mask, SIGINT);
281 1d3eb470 2021-03-20 op sigaddset(&mask, SIGTERM);
282 ca21e100 2021-02-04 op sigwait(&mask, &signo);
284 1d3eb470 2021-03-20 op return signo == SIGHUP;
288 ae08ec7d 2021-01-25 op drop_priv(void)
290 ae08ec7d 2021-01-25 op struct passwd *pw = NULL;
292 ae08ec7d 2021-01-25 op if (conf.chroot != NULL && conf.user == NULL)
293 ae08ec7d 2021-01-25 op fatal("can't chroot without an user to switch to after.");
295 ae08ec7d 2021-01-25 op if (conf.user != NULL) {
296 ae08ec7d 2021-01-25 op if ((pw = getpwnam(conf.user)) == NULL)
297 ae08ec7d 2021-01-25 op fatal("can't find user %s", conf.user);
300 ae08ec7d 2021-01-25 op if (conf.chroot != NULL) {
301 ae08ec7d 2021-01-25 op if (chroot(conf.chroot) != 0 || chdir("/") != 0)
302 ae08ec7d 2021-01-25 op fatal("%s: %s", conf.chroot, strerror(errno));
305 ae08ec7d 2021-01-25 op if (pw != NULL) {
306 ae08ec7d 2021-01-25 op if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1)
307 ae08ec7d 2021-01-25 op fatal("setresuid(%d): %s", pw->pw_uid,
308 ae08ec7d 2021-01-25 op strerror(errno));
311 ae08ec7d 2021-01-25 op if (getuid() == 0)
312 3abf91b0 2021-02-07 op log_warn(NULL, "not a good idea to run a network daemon as root");
316 3abf91b0 2021-02-07 op usage(const char *me)
318 3abf91b0 2021-02-07 op fprintf(stderr,
319 dbe262a4 2021-03-03 op "USAGE: %s [-fn] [-c config] | [-6h] [-d certs-dir] [-H host]\n"
320 aa372875 2021-02-10 op " [-p port] [-x cgi] [dir]\n",
325 376a5407 2021-02-23 op logger_init(void)
329 376a5407 2021-02-23 op if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, p) == -1)
330 376a5407 2021-02-23 op err(1, "socketpair");
332 376a5407 2021-02-23 op switch (fork()) {
334 376a5407 2021-02-23 op err(1, "fork");
336 bc99d868 2021-03-19 op signal(SIGHUP, SIG_IGN);
338 376a5407 2021-02-23 op setproctitle("logger");
339 bc99d868 2021-03-19 op imsg_init(&logibuf, p[1]);
341 bc99d868 2021-03-19 op _exit(logger_main(p[1], &logibuf));
344 bc99d868 2021-03-19 op imsg_init(&logibuf, p[0]);
350 bc99d868 2021-03-19 op serve(int argc, char **argv, struct imsgbuf *ibuf)
352 b8e64ccd 2021-03-31 op char path[PATH_MAX];
354 b8e64ccd 2021-03-31 op struct vhost *h;
355 b8e64ccd 2021-03-31 op struct location *l;
357 2c3e53da 2021-03-03 op if (config_path == NULL) {
358 d672b8fb 2021-02-03 op if (hostname == NULL)
359 d672b8fb 2021-02-03 op hostname = "localhost";
360 d672b8fb 2021-02-03 op if (certs_dir == NULL)
361 d672b8fb 2021-02-03 op certs_dir = data_dir();
362 d672b8fb 2021-02-03 op load_local_cert(hostname, certs_dir);
364 b8e64ccd 2021-03-31 op h = TAILQ_FIRST(&hosts);
365 b8e64ccd 2021-03-31 op h->domain = "*";
367 b8e64ccd 2021-03-31 op l = TAILQ_FIRST(&h->locations);
368 b8e64ccd 2021-03-31 op l->auto_index = 1;
369 b8e64ccd 2021-03-31 op l->match = "*";
371 d672b8fb 2021-02-03 op switch (argc) {
373 b8e64ccd 2021-03-31 op h->dir = getcwd(path, sizeof(path));
376 b8e64ccd 2021-03-31 op h->dir = absolutify_path(argv[0]);
379 d672b8fb 2021-02-03 op usage(getprogname());
383 b8e64ccd 2021-03-31 op log_notice(NULL, "serving %s on port %d", h->dir, conf.port);
386 d672b8fb 2021-02-03 op /* setup tls before dropping privileges: we don't want user
387 d672b8fb 2021-02-03 op * to put private certs inside the chroot. */
390 2c3e53da 2021-03-03 op for (i = 0; i < conf.prefork; ++i) {
391 2c3e53da 2021-03-03 op if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC,
392 2c3e53da 2021-03-03 op PF_UNSPEC, p) == -1)
393 2c3e53da 2021-03-03 op fatal("socketpair: %s", strerror(errno));
395 2c3e53da 2021-03-03 op switch (fork()) {
397 2c3e53da 2021-03-03 op fatal("fork: %s", strerror(errno));
398 2c3e53da 2021-03-03 op case 0: /* child */
400 bc99d868 2021-03-19 op imsg_init(&exibuf, p[1]);
401 2c3e53da 2021-03-03 op setproctitle("server");
402 bc99d868 2021-03-19 op _exit(listener_main(&exibuf));
405 bc99d868 2021-03-19 op imsg_init(&servibuf[i], p[0]);
409 2c3e53da 2021-03-03 op setproctitle("executor");
411 bc99d868 2021-03-19 op _exit(executor_main(ibuf));
415 b8e64ccd 2021-03-31 op setup_configless(int argc, char **argv, const char *cgi)
417 b8e64ccd 2021-03-31 op struct vhost *host;
418 b8e64ccd 2021-03-31 op struct location *loc;
420 b8e64ccd 2021-03-31 op host = xcalloc(1, sizeof(*host));
421 b8e64ccd 2021-03-31 op host->cgi = cgi;
422 b8e64ccd 2021-03-31 op TAILQ_INSERT_HEAD(&hosts, host, vhosts);
424 b8e64ccd 2021-03-31 op loc = xcalloc(1, sizeof(*loc));
425 b8e64ccd 2021-03-31 op TAILQ_INSERT_HEAD(&host->locations, loc, locations);
427 b8e64ccd 2021-03-31 op serve(argc, argv, NULL);
428 b8e64ccd 2021-03-31 op imsg_compose(&logibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
429 b8e64ccd 2021-03-31 op imsg_flush(&logibuf);
433 8d6ae384 2021-01-24 op main(int argc, char **argv)
435 d632468d 2021-03-20 op struct imsgbuf exibuf;
436 2c3e53da 2021-03-03 op int ch, conftest = 0, configless = 0;
437 ca21e100 2021-02-04 op int old_ipv6, old_port;
438 b8e64ccd 2021-03-31 op const char *cgi = NULL;
440 501e489c 2021-01-24 op init_config();
442 8904fa0e 2021-01-27 op while ((ch = getopt(argc, argv, "6c:d:fH:hnp:vx:")) != -1) {
443 3e4749f7 2020-10-02 op switch (ch) {
445 15902770 2021-01-15 op conf.ipv6 = 1;
446 8443bff7 2021-01-25 op configless = 1;
450 ca21e100 2021-02-04 op config_path = absolutify_path(optarg);
454 8443bff7 2021-01-25 op certs_dir = optarg;
455 8443bff7 2021-01-25 op configless = 1;
459 3abf91b0 2021-02-07 op conf.foreground = 1;
463 8443bff7 2021-01-25 op hostname = optarg;
464 8443bff7 2021-01-25 op configless = 1;
468 3e4749f7 2020-10-02 op usage(*argv);
472 15902770 2021-01-15 op conftest = 1;
476 15902770 2021-01-15 op conf.port = parse_portno(optarg);
477 8443bff7 2021-01-25 op configless = 1;
481 3abf91b0 2021-02-07 op conf.verbose++;
485 15902770 2021-01-15 op /* drop the starting / (if any) */
486 15902770 2021-01-15 op if (*optarg == '/')
488 b8e64ccd 2021-03-31 op cgi = optarg;
489 8443bff7 2021-01-25 op configless = 1;
493 3e4749f7 2020-10-02 op usage(*argv);
497 8443bff7 2021-01-25 op argc -= optind;
498 8443bff7 2021-01-25 op argv += optind;
500 d672b8fb 2021-02-03 op if (config_path == NULL) {
501 72bbed91 2021-01-27 op configless = 1;
502 3abf91b0 2021-02-07 op conf.foreground = 1;
503 2c3e53da 2021-03-03 op conf.prefork = 1;
504 3abf91b0 2021-02-07 op conf.verbose++;
507 d672b8fb 2021-02-03 op if (config_path != NULL && (argc > 0 || configless))
508 d672b8fb 2021-02-03 op err(1, "can't specify options in config mode.");
510 132cae8c 2021-01-18 op if (conftest) {
511 d672b8fb 2021-02-03 op parse_conf(config_path);
512 132cae8c 2021-01-18 op puts("config OK");
516 3abf91b0 2021-02-07 op if (!conf.foreground && !configless) {
517 0170ba02 2021-01-17 op if (daemon(1, 1) == -1)
518 d278a0c3 2021-02-23 op err(1, "daemon");
521 d672b8fb 2021-02-03 op if (config_path != NULL)
522 d672b8fb 2021-02-03 op parse_conf(config_path);
524 d278a0c3 2021-02-23 op logger_init();
526 d672b8fb 2021-02-03 op sock4 = make_socket(conf.port, AF_INET);
528 d672b8fb 2021-02-03 op if (conf.ipv6)
529 d672b8fb 2021-02-03 op sock6 = make_socket(conf.port, AF_INET6);
531 3841a369 2021-04-20 op signal(SIGPIPE, SIG_IGN);
532 3841a369 2021-04-20 op signal(SIGCHLD, SIG_IGN);
534 bc99d868 2021-03-19 op if (configless) {
535 b8e64ccd 2021-03-31 op setup_configless(argc, argv, cgi);
539 b9c9123b 2021-03-20 op /* Linux seems to call the event handlers even when we're
540 8e09ee1d 2021-03-20 op * doing a sigwait. These dummy handlers is here to avoid
541 5d1474a5 2021-04-20 op * being terminated on SIGHUP, SIGINT or SIGTERM. */
542 b9c9123b 2021-03-20 op signal(SIGHUP, dummy_handler);
543 b9c9123b 2021-03-20 op signal(SIGINT, dummy_handler);
544 b9c9123b 2021-03-20 op signal(SIGTERM, dummy_handler);
546 ca21e100 2021-02-04 op /* wait a sighup and reload the daemon */
550 bc99d868 2021-03-19 op if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC,
551 bc99d868 2021-03-19 op PF_UNSPEC, p) == -1)
552 bc99d868 2021-03-19 op fatal("socketpair: %s", strerror(errno));
554 ca21e100 2021-02-04 op switch (fork()) {
556 ca21e100 2021-02-04 op fatal("fork: %s", strerror(errno));
559 bc99d868 2021-03-19 op imsg_init(&exibuf, p[1]);
560 bc99d868 2021-03-19 op _exit(serve(argc, argv, &exibuf));
564 bc99d868 2021-03-19 op imsg_init(&exibuf, p[0]);
566 1d3eb470 2021-03-20 op if (!wait_signal())
569 3abf91b0 2021-02-07 op log_info(NULL, "reloading configuration %s", config_path);
571 bc99d868 2021-03-19 op /* close the executor (it'll close the servers too) */
572 bc99d868 2021-03-19 op imsg_compose(&exibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
573 bc99d868 2021-03-19 op imsg_flush(&exibuf);
576 ca21e100 2021-02-04 op old_ipv6 = conf.ipv6;
577 ca21e100 2021-02-04 op old_port = conf.port;
579 ca21e100 2021-02-04 op free_config();
580 ca21e100 2021-02-04 op init_config();
581 ca21e100 2021-02-04 op parse_conf(config_path);
583 ca21e100 2021-02-04 op if (old_port != conf.port) {
584 ca21e100 2021-02-04 op close(sock4);
585 ca21e100 2021-02-04 op close(sock6);
590 ca21e100 2021-02-04 op if (sock6 != -1 && old_ipv6 != conf.ipv6) {
591 ca21e100 2021-02-04 op close(sock6);
595 ca21e100 2021-02-04 op if (sock4 == -1)
596 ca21e100 2021-02-04 op sock4 = make_socket(conf.port, AF_INET);
597 ca21e100 2021-02-04 op if (sock6 == -1 && conf.ipv6)
598 ca21e100 2021-02-04 op sock6 = make_socket(conf.port, AF_INET6);
601 1d3eb470 2021-03-20 op imsg_compose(&exibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
602 1d3eb470 2021-03-20 op imsg_flush(&exibuf);
604 1d3eb470 2021-03-20 op imsg_compose(&logibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
605 1d3eb470 2021-03-20 op imsg_flush(&logibuf);