2 a555e0d6 2022-07-04 op * Copyright (c) 2020, 2021, 2022 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 5777923b 2021-06-29 op #include <getopt.h>
24 7e1df73d 2021-03-31 op #include <libgen.h>
25 bcf5d929 2021-02-01 op #include <limits.h>
26 ae08ec7d 2021-01-25 op #include <pwd.h>
27 0cf902af 2020-11-03 op #include <signal.h>
28 3e4749f7 2020-10-02 op #include <string.h>
30 32fbc478 2022-09-08 op static const char *opts = "c:D:fhnP:Vv";
32 e5d82d94 2022-03-19 op static const struct option longopts[] = {
33 5777923b 2021-06-29 op {"help", no_argument, NULL, 'h'},
34 5777923b 2021-06-29 op {"version", no_argument, NULL, 'V'},
35 5777923b 2021-06-29 op {NULL, 0, NULL, 0},
38 8ad1c570 2021-05-09 op struct fcgi fcgi[FCGI_MAX];
40 b8e64ccd 2021-03-31 op struct vhosthead hosts;
42 bc99d868 2021-03-19 op int sock4, sock6;
44 bc99d868 2021-03-19 op struct imsgbuf logibuf, exibuf, servibuf[PROC_MAX];
46 32fbc478 2022-09-08 op const char *config_path = "/etc/gmid.conf";
47 32fbc478 2022-09-08 op const char *pidfile;
49 15902770 2021-01-15 op struct conf conf;
51 ca21e100 2021-02-04 op struct tls_config *tlsconf;
52 ae08ec7d 2021-01-25 op struct tls *ctx;
55 b9c9123b 2021-03-20 op dummy_handler(int signo)
61 ae08ec7d 2021-01-25 op load_vhosts(void)
63 fdea6aa0 2021-04-30 op struct vhost *h;
64 fdea6aa0 2021-04-30 op struct location *l;
66 b8e64ccd 2021-03-31 op TAILQ_FOREACH(h, &hosts, vhosts) {
67 fdea6aa0 2021-04-30 op TAILQ_FOREACH(l, &h->locations, locations) {
68 fdea6aa0 2021-04-30 op if (l->dir == NULL)
70 fdea6aa0 2021-04-30 op if ((l->dirfd = open(l->dir, O_RDONLY | O_DIRECTORY)) == -1)
71 807869c1 2021-10-07 op fatal("open %s for domain %s: %s", l->dir, h->domain,
72 807869c1 2021-10-07 op strerror(errno));
78 9468027b 2020-10-15 op make_socket(int port, int family)
81 9468027b 2020-10-15 op struct sockaddr_in addr4;
82 9468027b 2020-10-15 op struct sockaddr_in6 addr6;
83 9468027b 2020-10-15 op struct sockaddr *addr;
84 9468027b 2020-10-15 op socklen_t len;
86 81e0f000 2021-09-24 op switch (family) {
88 df0c2926 2021-09-24 op memset(&addr4, 0, sizeof(addr4));
89 9468027b 2020-10-15 op addr4.sin_family = family;
90 9468027b 2020-10-15 op addr4.sin_port = htons(port);
91 9468027b 2020-10-15 op addr4.sin_addr.s_addr = INADDR_ANY;
92 9468027b 2020-10-15 op addr = (struct sockaddr*)&addr4;
93 9468027b 2020-10-15 op len = sizeof(addr4);
96 9468027b 2020-10-15 op case AF_INET6:
97 df0c2926 2021-09-24 op memset(&addr6, 0, sizeof(addr6));
98 9468027b 2020-10-15 op addr6.sin6_family = AF_INET6;
99 9468027b 2020-10-15 op addr6.sin6_port = htons(port);
100 9468027b 2020-10-15 op addr6.sin6_addr = in6addr_any;
101 9468027b 2020-10-15 op addr = (struct sockaddr*)&addr6;
102 9468027b 2020-10-15 op len = sizeof(addr6);
106 9468027b 2020-10-15 op /* unreachable */
110 9468027b 2020-10-15 op if ((sock = socket(family, SOCK_STREAM, 0)) == -1)
111 80bbcad5 2021-01-10 op fatal("socket: %s", strerror(errno));
114 3e4749f7 2020-10-02 op if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v)) == -1)
115 80bbcad5 2021-01-10 op fatal("setsockopt(SO_REUSEADDR): %s", strerror(errno));
118 3e4749f7 2020-10-02 op if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &v, sizeof(v)) == -1)
119 80bbcad5 2021-01-10 op fatal("setsockopt(SO_REUSEPORT): %s", strerror(errno));
121 592fd624 2020-10-07 op mark_nonblock(sock);
123 9468027b 2020-10-15 op if (bind(sock, addr, len) == -1)
124 80bbcad5 2021-01-10 op fatal("bind: %s", strerror(errno));
126 3e4749f7 2020-10-02 op if (listen(sock, 16) == -1)
127 80bbcad5 2021-01-10 op fatal("listen: %s", strerror(errno));
133 ff05125e 2021-10-15 op add_keypair(struct vhost *h)
135 ff05125e 2021-10-15 op if (h->ocsp == NULL) {
136 ff05125e 2021-10-15 op if (tls_config_add_keypair_file(tlsconf, h->cert, h->key) == -1)
137 ff05125e 2021-10-15 op fatal("failed to load the keypair (%s, %s)",
138 ff05125e 2021-10-15 op h->cert, h->key);
140 7fa67176 2021-10-15 op if (tls_config_add_keypair_ocsp_file(tlsconf, h->cert, h->key,
141 7fa67176 2021-10-15 op h->ocsp) == -1)
142 ff05125e 2021-10-15 op fatal("failed to load the keypair (%s, %s, %s)",
143 ff05125e 2021-10-15 op h->cert, h->key, h->ocsp);
148 ae08ec7d 2021-01-25 op setup_tls(void)
150 ae08ec7d 2021-01-25 op struct vhost *h;
152 881a9dd9 2021-01-16 op if ((tlsconf = tls_config_new()) == NULL)
153 132cae8c 2021-01-18 op fatal("tls_config_new");
155 881a9dd9 2021-01-16 op /* optionally accept client certs, but don't try to verify them */
156 881a9dd9 2021-01-16 op tls_config_verify_client_optional(tlsconf);
157 881a9dd9 2021-01-16 op tls_config_insecure_noverifycert(tlsconf);
159 881a9dd9 2021-01-16 op if (tls_config_set_protocols(tlsconf, conf.protos) == -1)
160 132cae8c 2021-01-18 op fatal("tls_config_set_protocols");
162 881a9dd9 2021-01-16 op if ((ctx = tls_server()) == NULL)
163 132cae8c 2021-01-18 op fatal("tls_server failure");
165 b8e64ccd 2021-03-31 op h = TAILQ_FIRST(&hosts);
167 ae08ec7d 2021-01-25 op /* we need to set something, then we can add how many key we want */
168 b8e64ccd 2021-03-31 op if (tls_config_set_keypair_file(tlsconf, h->cert, h->key))
169 ca21e100 2021-02-04 op fatal("tls_config_set_keypair_file failed for (%s, %s)",
170 b8e64ccd 2021-03-31 op h->cert, h->key);
172 7fa67176 2021-10-15 op /* same for OCSP */
173 ff05125e 2021-10-15 op if (h->ocsp != NULL &&
174 ff05125e 2021-10-15 op tls_config_set_ocsp_staple_file(tlsconf, h->ocsp) == -1)
175 ff05125e 2021-10-15 op fatal("tls_config_set_ocsp_staple_file failed for (%s)",
178 ff05125e 2021-10-15 op while ((h = TAILQ_NEXT(h, vhosts)) != NULL)
179 ff05125e 2021-10-15 op add_keypair(h);
181 881a9dd9 2021-01-16 op if (tls_configure(ctx, tlsconf) == -1)
182 132cae8c 2021-01-18 op fatal("tls_configure: %s", tls_error(ctx));
186 bc99d868 2021-03-19 op listener_main(struct imsgbuf *ibuf)
189 54203115 2022-04-08 op if (!conf.mime.skip_defaults && load_default_mime(&conf.mime) == -1)
190 d8d170aa 2022-04-08 op fatal("load_default_mime: %s", strerror(errno));
191 18bd8391 2022-04-08 op sort_mime(&conf.mime);
192 ae08ec7d 2021-01-25 op load_vhosts();
193 bc99d868 2021-03-19 op loop(ctx, sock4, sock6, ibuf);
198 8d6ae384 2021-01-24 op init_config(void)
200 b8e64ccd 2021-03-31 op TAILQ_INIT(&hosts);
202 15902770 2021-01-15 op conf.port = 1965;
203 15902770 2021-01-15 op conf.ipv6 = 0;
204 5bc3c98e 2021-01-15 op conf.protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3;
206 b2a6b613 2021-01-21 op init_mime(&conf.mime);
208 ae08ec7d 2021-01-25 op conf.chroot = NULL;
209 ae08ec7d 2021-01-25 op conf.user = NULL;
211 a709ddf5 2021-02-07 op conf.prefork = 3;
215 ca21e100 2021-02-04 op free_config(void)
217 b8e64ccd 2021-03-31 op struct vhost *h, *th;
218 b8e64ccd 2021-03-31 op struct location *l, *tl;
219 b7967bc1 2021-01-02 op struct proxy *p, *tp;
220 9cc630aa 2021-04-28 op struct envlist *e, *te;
221 cc8c2901 2021-04-29 op struct alist *a, *ta;
224 419a4235 2021-04-28 op v = conf.verbose;
226 d8d170aa 2022-04-08 op free_mime(&conf.mime);
227 ca21e100 2021-02-04 op free(conf.chroot);
228 ca21e100 2021-02-04 op free(conf.user);
229 ca21e100 2021-02-04 op memset(&conf, 0, sizeof(conf));
231 419a4235 2021-04-28 op conf.verbose = v;
233 b8e64ccd 2021-03-31 op TAILQ_FOREACH_SAFE(h, &hosts, vhosts, th) {
234 b8e64ccd 2021-03-31 op TAILQ_FOREACH_SAFE(l, &h->locations, locations, tl) {
235 b8e64ccd 2021-03-31 op TAILQ_REMOVE(&h->locations, l, locations);
237 ca21e100 2021-02-04 op free((char*)l->match);
238 ca21e100 2021-02-04 op free((char*)l->lang);
239 ca21e100 2021-02-04 op free((char*)l->default_mime);
240 ca21e100 2021-02-04 op free((char*)l->index);
241 6abda252 2021-02-06 op free((char*)l->block_fmt);
242 fdea6aa0 2021-04-30 op free((char*)l->dir);
244 fdea6aa0 2021-04-30 op if (l->dirfd != -1)
245 fdea6aa0 2021-04-30 op close(l->dirfd);
250 9cc630aa 2021-04-28 op TAILQ_FOREACH_SAFE(e, &h->env, envs, te) {
251 3b33eab3 2021-06-12 op TAILQ_REMOVE(&h->env, e, envs);
253 ab1e0169 2021-06-12 op free(e->name);
254 ab1e0169 2021-06-12 op free(e->value);
258 ab1e0169 2021-06-12 op TAILQ_FOREACH_SAFE(e, &h->params, envs, te) {
259 ab1e0169 2021-06-12 op TAILQ_REMOVE(&h->params, e, envs);
261 9cc630aa 2021-04-28 op free(e->name);
262 9cc630aa 2021-04-28 op free(e->value);
266 cc8c2901 2021-04-29 op TAILQ_FOREACH_SAFE(a, &h->aliases, aliases, ta) {
267 3b33eab3 2021-06-12 op TAILQ_REMOVE(&h->aliases, a, aliases);
269 cc8c2901 2021-04-29 op free(a->alias);
273 b7967bc1 2021-01-02 op TAILQ_FOREACH_SAFE(p, &h->proxies, proxies, tp) {
274 b7967bc1 2021-01-02 op TAILQ_REMOVE(&h->proxies, p, proxies);
276 b7967bc1 2021-01-02 op free(p->match_proto);
277 b7967bc1 2021-01-02 op free(p->match_host);
278 b7967bc1 2021-01-02 op free(p->host);
279 1cdea97b 2022-01-30 op free(p->sni);
280 b7967bc1 2021-01-02 op tls_unload_file(p->cert, p->certlen);
281 b7967bc1 2021-01-02 op tls_unload_file(p->key, p->keylen);
285 fdea6aa0 2021-04-30 op free((char*)h->domain);
286 fdea6aa0 2021-04-30 op free((char*)h->cert);
287 fdea6aa0 2021-04-30 op free((char*)h->key);
288 193380ea 2021-10-24 op free((char*)h->ocsp);
289 fdea6aa0 2021-04-30 op free((char*)h->entrypoint);
291 b8e64ccd 2021-03-31 op TAILQ_REMOVE(&hosts, h, vhosts);
295 8ad1c570 2021-05-09 op for (i = 0; i < FCGI_MAX; ++i) {
296 8ad1c570 2021-05-09 op if (fcgi[i].path == NULL && fcgi[i].prog == NULL)
298 8ad1c570 2021-05-09 op free(fcgi[i].path);
299 8ad1c570 2021-05-09 op free(fcgi[i].port);
300 8ad1c570 2021-05-09 op free(fcgi[i].prog);
302 ef945cf4 2021-07-06 op fcgi[i].path = NULL;
303 ef945cf4 2021-07-06 op fcgi[i].port = NULL;
304 ef945cf4 2021-07-06 op fcgi[i].prog = NULL;
307 ca21e100 2021-02-04 op tls_free(ctx);
308 ca21e100 2021-02-04 op tls_config_free(tlsconf);
312 1d3eb470 2021-03-20 op wait_signal(void)
314 ca21e100 2021-02-04 op sigset_t mask;
317 ca21e100 2021-02-04 op sigemptyset(&mask);
318 ca21e100 2021-02-04 op sigaddset(&mask, SIGHUP);
319 1d3eb470 2021-03-20 op sigaddset(&mask, SIGINT);
320 1d3eb470 2021-03-20 op sigaddset(&mask, SIGTERM);
321 ca21e100 2021-02-04 op sigwait(&mask, &signo);
323 1d3eb470 2021-03-20 op return signo == SIGHUP;
327 ae08ec7d 2021-01-25 op drop_priv(void)
329 ae08ec7d 2021-01-25 op struct passwd *pw = NULL;
331 ae08ec7d 2021-01-25 op if (conf.chroot != NULL && conf.user == NULL)
332 ae08ec7d 2021-01-25 op fatal("can't chroot without an user to switch to after.");
334 ae08ec7d 2021-01-25 op if (conf.user != NULL) {
335 ae08ec7d 2021-01-25 op if ((pw = getpwnam(conf.user)) == NULL)
336 ae08ec7d 2021-01-25 op fatal("can't find user %s", conf.user);
339 ae08ec7d 2021-01-25 op if (conf.chroot != NULL) {
340 ae08ec7d 2021-01-25 op if (chroot(conf.chroot) != 0 || chdir("/") != 0)
341 ae08ec7d 2021-01-25 op fatal("%s: %s", conf.chroot, strerror(errno));
344 ae08ec7d 2021-01-25 op if (pw != NULL) {
345 ae08ec7d 2021-01-25 op if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1)
346 ae08ec7d 2021-01-25 op fatal("setresuid(%d): %s", pw->pw_uid,
347 ae08ec7d 2021-01-25 op strerror(errno));
350 ae08ec7d 2021-01-25 op if (getuid() == 0)
351 3abf91b0 2021-02-07 op log_warn(NULL, "not a good idea to run a network daemon as root");
357 3abf91b0 2021-02-07 op fprintf(stderr,
358 0be2a537 2021-06-29 op "Version: " GMID_STRING "\n"
359 32fbc478 2022-09-08 op "Usage: %s [-fnv] [-c config] [-D macro=value] [-P pidfile]\n",
360 9327bc04 2021-06-29 op getprogname());
364 376a5407 2021-02-23 op logger_init(void)
368 376a5407 2021-02-23 op if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, p) == -1)
369 376a5407 2021-02-23 op err(1, "socketpair");
371 376a5407 2021-02-23 op switch (fork()) {
373 376a5407 2021-02-23 op err(1, "fork");
375 bc99d868 2021-03-19 op signal(SIGHUP, SIG_IGN);
377 376a5407 2021-02-23 op setproctitle("logger");
378 bc99d868 2021-03-19 op imsg_init(&logibuf, p[1]);
380 bc99d868 2021-03-19 op _exit(logger_main(p[1], &logibuf));
383 bc99d868 2021-03-19 op imsg_init(&logibuf, p[0]);
393 d672b8fb 2021-02-03 op /* setup tls before dropping privileges: we don't want user
394 d672b8fb 2021-02-03 op * to put private certs inside the chroot. */
397 2c3e53da 2021-03-03 op for (i = 0; i < conf.prefork; ++i) {
398 2c3e53da 2021-03-03 op if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC,
399 2c3e53da 2021-03-03 op PF_UNSPEC, p) == -1)
400 2c3e53da 2021-03-03 op fatal("socketpair: %s", strerror(errno));
402 2c3e53da 2021-03-03 op switch (fork()) {
404 2c3e53da 2021-03-03 op fatal("fork: %s", strerror(errno));
405 2c3e53da 2021-03-03 op case 0: /* child */
407 bc99d868 2021-03-19 op imsg_init(&exibuf, p[1]);
408 2c3e53da 2021-03-03 op setproctitle("server");
409 bc99d868 2021-03-19 op _exit(listener_main(&exibuf));
412 bc99d868 2021-03-19 op imsg_init(&servibuf[i], p[0]);
418 419a4235 2021-04-28 op write_pidfile(const char *pidfile)
420 419a4235 2021-04-28 op struct flock lock;
423 419a4235 2021-04-28 op if (pidfile == NULL)
426 419a4235 2021-04-28 op if ((fd = open(pidfile, O_WRONLY|O_CREAT|O_CLOEXEC, 0600)) == -1)
427 419a4235 2021-04-28 op fatal("can't open pidfile %s: %s", pidfile, strerror(errno));
429 419a4235 2021-04-28 op lock.l_start = 0;
430 419a4235 2021-04-28 op lock.l_len = 0;
431 419a4235 2021-04-28 op lock.l_type = F_WRLCK;
432 419a4235 2021-04-28 op lock.l_whence = SEEK_SET;
434 419a4235 2021-04-28 op if (fcntl(fd, F_SETLK, &lock) == -1)
435 419a4235 2021-04-28 op fatal("can't lock %s, gmid is already running?", pidfile);
437 419a4235 2021-04-28 op if (ftruncate(fd, 0) == -1)
438 419a4235 2021-04-28 op fatal("ftruncate: %s: %s", pidfile, strerror(errno));
440 419a4235 2021-04-28 op dprintf(fd, "%d\n", getpid());
446 8d6ae384 2021-01-24 op main(int argc, char **argv)
448 32fbc478 2022-09-08 op int i, ch, conftest = 0;
449 8e8b2e25 2021-04-28 op int pidfd, old_ipv6, old_port;
451 8a50fc03 2021-07-07 op logger_init();
452 501e489c 2021-01-24 op init_config();
454 5777923b 2021-06-29 op while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) {
455 3e4749f7 2020-10-02 op switch (ch) {
457 ca21e100 2021-02-04 op config_path = absolutify_path(optarg);
461 f98e9045 2021-06-29 op if (cmdline_symset(optarg) == -1)
462 8a50fc03 2021-07-07 op fatal("could not parse macro definition: %s",
467 3abf91b0 2021-02-07 op conf.foreground = 1;
479 8e8b2e25 2021-04-28 op pidfile = optarg;
483 fdb43a4c 2021-06-29 op puts("Version: " GMID_STRING);
487 3abf91b0 2021-02-07 op conf.verbose++;
495 8443bff7 2021-01-25 op argc -= optind;
496 8443bff7 2021-01-25 op argv += optind;
498 32fbc478 2022-09-08 op if (argc != 0)
501 32fbc478 2022-09-08 op parse_conf(config_path);
503 132cae8c 2021-01-18 op if (conftest) {
504 f0a01fc7 2021-10-09 op fprintf(stderr, "config OK\n");
505 f0a01fc7 2021-10-09 op if (conftest > 1)
506 f0a01fc7 2021-10-09 op print_conf();
510 32fbc478 2022-09-08 op if (!conf.foreground) {
511 8a50fc03 2021-07-07 op /* log to syslog */
512 8a50fc03 2021-07-07 op imsg_compose(&logibuf, IMSG_LOG_TYPE, 0, 0, -1, NULL, 0);
513 8a50fc03 2021-07-07 op imsg_flush(&logibuf);
515 0170ba02 2021-01-17 op if (daemon(1, 1) == -1)
516 8a50fc03 2021-07-07 op fatal("daemon: %s", strerror(errno));
519 d672b8fb 2021-02-03 op sock4 = make_socket(conf.port, AF_INET);
521 d672b8fb 2021-02-03 op if (conf.ipv6)
522 d672b8fb 2021-02-03 op sock6 = make_socket(conf.port, AF_INET6);
524 3841a369 2021-04-20 op signal(SIGPIPE, SIG_IGN);
526 8e8b2e25 2021-04-28 op pidfd = write_pidfile(pidfile);
529 a8a1f439 2021-07-07 op * Linux seems to call the event handlers even when we're
530 1b333122 2021-04-26 op * doing a sigwait. These dummy handlers are here to avoid
531 a8a1f439 2021-07-07 op * being terminated on SIGHUP, SIGINT or SIGTERM.
533 b9c9123b 2021-03-20 op signal(SIGHUP, dummy_handler);
534 b9c9123b 2021-03-20 op signal(SIGINT, dummy_handler);
535 b9c9123b 2021-03-20 op signal(SIGTERM, dummy_handler);
537 ca21e100 2021-02-04 op /* wait a sighup and reload the daemon */
541 32fbc478 2022-09-08 op if (!wait_signal())
544 3abf91b0 2021-02-07 op log_info(NULL, "reloading configuration %s", config_path);
546 d29a2ee2 2022-09-06 op /* close the servers */
547 d29a2ee2 2022-09-06 op for (i = 0; i < conf.prefork; ++i) {
548 d29a2ee2 2022-09-06 op imsg_compose(&servibuf[i], IMSG_QUIT, 0, 0, -1, NULL, 0);
549 d29a2ee2 2022-09-06 op imsg_flush(&servibuf[i]);
550 d29a2ee2 2022-09-06 op close(servibuf[i].fd);
553 ca21e100 2021-02-04 op old_ipv6 = conf.ipv6;
554 ca21e100 2021-02-04 op old_port = conf.port;
556 ca21e100 2021-02-04 op free_config();
557 ca21e100 2021-02-04 op init_config();
558 ca21e100 2021-02-04 op parse_conf(config_path);
560 ca21e100 2021-02-04 op if (old_port != conf.port) {
561 ca21e100 2021-02-04 op close(sock4);
562 ca21e100 2021-02-04 op close(sock6);
567 ca21e100 2021-02-04 op if (sock6 != -1 && old_ipv6 != conf.ipv6) {
568 ca21e100 2021-02-04 op close(sock6);
572 ca21e100 2021-02-04 op if (sock4 == -1)
573 ca21e100 2021-02-04 op sock4 = make_socket(conf.port, AF_INET);
574 ca21e100 2021-02-04 op if (sock6 == -1 && conf.ipv6)
575 ca21e100 2021-02-04 op sock6 = make_socket(conf.port, AF_INET6);
578 1d3eb470 2021-03-20 op imsg_compose(&exibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
579 1d3eb470 2021-03-20 op imsg_flush(&exibuf);
581 1d3eb470 2021-03-20 op imsg_compose(&logibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
582 1d3eb470 2021-03-20 op imsg_flush(&logibuf);
584 8e8b2e25 2021-04-28 op if (pidfd != -1)
585 8e8b2e25 2021-04-28 op close(pidfd);