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 15902770 2021-01-15 op struct vhost hosts[HOSTSLEN];
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;
99 8443bff7 2021-01-25 op if (asprintf(&cert, "%s/%s.cert.pem", dir, hostname) == -1)
100 8443bff7 2021-01-25 op errx(1, "asprintf");
101 8443bff7 2021-01-25 op if (asprintf(&key, "%s/%s.key.pem", dir, hostname) == -1)
102 8443bff7 2021-01-25 op errx(1, "asprintf");
104 8443bff7 2021-01-25 op if (access(cert, R_OK) == -1 || access(key, R_OK) == -1)
105 8443bff7 2021-01-25 op gen_certificate(hostname, cert, key);
107 8443bff7 2021-01-25 op hosts[0].cert = cert;
108 8443bff7 2021-01-25 op hosts[0].key = key;
109 8443bff7 2021-01-25 op hosts[0].domain = hostname;
113 ae08ec7d 2021-01-25 op load_vhosts(void)
115 15902770 2021-01-15 op struct vhost *h;
117 15902770 2021-01-15 op for (h = hosts; h->domain != NULL; ++h) {
118 d3a08f4d 2021-01-17 op if ((h->dirfd = open(h->dir, O_RDONLY | O_DIRECTORY)) == -1)
119 132cae8c 2021-01-18 op fatal("open %s for domain %s", h->dir, h->domain);
124 9468027b 2020-10-15 op make_socket(int port, int family)
127 9468027b 2020-10-15 op struct sockaddr_in addr4;
128 9468027b 2020-10-15 op struct sockaddr_in6 addr6;
129 9468027b 2020-10-15 op struct sockaddr *addr;
130 9468027b 2020-10-15 op socklen_t len;
132 9468027b 2020-10-15 op switch (family) {
133 9468027b 2020-10-15 op case AF_INET:
134 9468027b 2020-10-15 op bzero(&addr4, sizeof(addr4));
135 9468027b 2020-10-15 op addr4.sin_family = family;
136 9468027b 2020-10-15 op addr4.sin_port = htons(port);
137 9468027b 2020-10-15 op addr4.sin_addr.s_addr = INADDR_ANY;
138 9468027b 2020-10-15 op addr = (struct sockaddr*)&addr4;
139 9468027b 2020-10-15 op len = sizeof(addr4);
142 9468027b 2020-10-15 op case AF_INET6:
143 9468027b 2020-10-15 op bzero(&addr6, sizeof(addr6));
144 9468027b 2020-10-15 op addr6.sin6_family = AF_INET6;
145 9468027b 2020-10-15 op addr6.sin6_port = htons(port);
146 9468027b 2020-10-15 op addr6.sin6_addr = in6addr_any;
147 9468027b 2020-10-15 op addr = (struct sockaddr*)&addr6;
148 9468027b 2020-10-15 op len = sizeof(addr6);
152 9468027b 2020-10-15 op /* unreachable */
156 9468027b 2020-10-15 op if ((sock = socket(family, SOCK_STREAM, 0)) == -1)
157 80bbcad5 2021-01-10 op fatal("socket: %s", strerror(errno));
160 3e4749f7 2020-10-02 op if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v)) == -1)
161 80bbcad5 2021-01-10 op fatal("setsockopt(SO_REUSEADDR): %s", strerror(errno));
164 3e4749f7 2020-10-02 op if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &v, sizeof(v)) == -1)
165 80bbcad5 2021-01-10 op fatal("setsockopt(SO_REUSEPORT): %s", strerror(errno));
167 592fd624 2020-10-07 op mark_nonblock(sock);
169 9468027b 2020-10-15 op if (bind(sock, addr, len) == -1)
170 80bbcad5 2021-01-10 op fatal("bind: %s", strerror(errno));
172 3e4749f7 2020-10-02 op if (listen(sock, 16) == -1)
173 80bbcad5 2021-01-10 op fatal("listen: %s", strerror(errno));
179 ae08ec7d 2021-01-25 op setup_tls(void)
181 ae08ec7d 2021-01-25 op struct vhost *h;
183 881a9dd9 2021-01-16 op if ((tlsconf = tls_config_new()) == NULL)
184 132cae8c 2021-01-18 op fatal("tls_config_new");
186 881a9dd9 2021-01-16 op /* optionally accept client certs, but don't try to verify them */
187 881a9dd9 2021-01-16 op tls_config_verify_client_optional(tlsconf);
188 881a9dd9 2021-01-16 op tls_config_insecure_noverifycert(tlsconf);
190 881a9dd9 2021-01-16 op if (tls_config_set_protocols(tlsconf, conf.protos) == -1)
191 132cae8c 2021-01-18 op fatal("tls_config_set_protocols");
193 881a9dd9 2021-01-16 op if ((ctx = tls_server()) == NULL)
194 132cae8c 2021-01-18 op fatal("tls_server failure");
196 ae08ec7d 2021-01-25 op /* we need to set something, then we can add how many key we want */
197 ae08ec7d 2021-01-25 op if (tls_config_set_keypair_file(tlsconf, hosts->cert, hosts->key))
198 ca21e100 2021-02-04 op fatal("tls_config_set_keypair_file failed for (%s, %s)",
199 ca21e100 2021-02-04 op hosts->cert, hosts->key);
201 8443bff7 2021-01-25 op for (h = &hosts[1]; h->domain != NULL; ++h) {
202 ae08ec7d 2021-01-25 op if (tls_config_add_keypair_file(tlsconf, h->cert, h->key) == -1)
203 ae08ec7d 2021-01-25 op fatal("failed to load the keypair (%s, %s)",
204 ae08ec7d 2021-01-25 op h->cert, h->key);
207 881a9dd9 2021-01-16 op if (tls_configure(ctx, tlsconf) == -1)
208 132cae8c 2021-01-18 op fatal("tls_configure: %s", tls_error(ctx));
212 bc99d868 2021-03-19 op listener_main(struct imsgbuf *ibuf)
215 ae08ec7d 2021-01-25 op load_default_mime(&conf.mime);
216 ae08ec7d 2021-01-25 op load_vhosts();
217 bc99d868 2021-03-19 op loop(ctx, sock4, sock6, ibuf);
222 8d6ae384 2021-01-24 op init_config(void)
226 15902770 2021-01-15 op bzero(hosts, sizeof(hosts));
227 15902770 2021-01-15 op for (i = 0; i < HOSTSLEN; ++i)
228 15902770 2021-01-15 op hosts[i].dirfd = -1;
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 /* we'll change this to 0 when running without config. */
240 a709ddf5 2021-02-07 op conf.prefork = 3;
244 ca21e100 2021-02-04 op free_config(void)
246 ca21e100 2021-02-04 op struct vhost *h;
247 ca21e100 2021-02-04 op struct location *l;
249 ca21e100 2021-02-04 op free(conf.chroot);
250 ca21e100 2021-02-04 op free(conf.user);
251 ca21e100 2021-02-04 op memset(&conf, 0, sizeof(conf));
253 ca21e100 2021-02-04 op for (h = hosts; h->domain != NULL; ++h) {
254 ca21e100 2021-02-04 op free((char*)h->domain);
255 ca21e100 2021-02-04 op free((char*)h->cert);
256 ca21e100 2021-02-04 op free((char*)h->key);
257 ca21e100 2021-02-04 op free((char*)h->dir);
258 ca21e100 2021-02-04 op free((char*)h->cgi);
259 e3ddf390 2021-02-06 op free((char*)h->entrypoint);
261 ca21e100 2021-02-04 op for (l = h->locations; l->match != NULL; ++l) {
262 ca21e100 2021-02-04 op free((char*)l->match);
263 ca21e100 2021-02-04 op free((char*)l->lang);
264 ca21e100 2021-02-04 op free((char*)l->default_mime);
265 ca21e100 2021-02-04 op free((char*)l->index);
266 6abda252 2021-02-06 op free((char*)l->block_fmt);
269 ca21e100 2021-02-04 op memset(hosts, 0, sizeof(hosts));
271 ca21e100 2021-02-04 op tls_free(ctx);
272 ca21e100 2021-02-04 op tls_config_free(tlsconf);
276 1d3eb470 2021-03-20 op wait_signal(void)
278 ca21e100 2021-02-04 op sigset_t mask;
281 ca21e100 2021-02-04 op sigemptyset(&mask);
282 ca21e100 2021-02-04 op sigaddset(&mask, SIGHUP);
283 1d3eb470 2021-03-20 op sigaddset(&mask, SIGINT);
284 1d3eb470 2021-03-20 op sigaddset(&mask, SIGTERM);
285 ca21e100 2021-02-04 op sigwait(&mask, &signo);
287 1d3eb470 2021-03-20 op return signo == SIGHUP;
291 ae08ec7d 2021-01-25 op drop_priv(void)
293 ae08ec7d 2021-01-25 op struct passwd *pw = NULL;
295 ae08ec7d 2021-01-25 op if (conf.chroot != NULL && conf.user == NULL)
296 ae08ec7d 2021-01-25 op fatal("can't chroot without an user to switch to after.");
298 ae08ec7d 2021-01-25 op if (conf.user != NULL) {
299 ae08ec7d 2021-01-25 op if ((pw = getpwnam(conf.user)) == NULL)
300 ae08ec7d 2021-01-25 op fatal("can't find user %s", conf.user);
303 ae08ec7d 2021-01-25 op if (conf.chroot != NULL) {
304 ae08ec7d 2021-01-25 op if (chroot(conf.chroot) != 0 || chdir("/") != 0)
305 ae08ec7d 2021-01-25 op fatal("%s: %s", conf.chroot, strerror(errno));
308 ae08ec7d 2021-01-25 op if (pw != NULL) {
309 ae08ec7d 2021-01-25 op if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1)
310 ae08ec7d 2021-01-25 op fatal("setresuid(%d): %s", pw->pw_uid,
311 ae08ec7d 2021-01-25 op strerror(errno));
314 ae08ec7d 2021-01-25 op if (getuid() == 0)
315 3abf91b0 2021-02-07 op log_warn(NULL, "not a good idea to run a network daemon as root");
319 3abf91b0 2021-02-07 op usage(const char *me)
321 3abf91b0 2021-02-07 op fprintf(stderr,
322 dbe262a4 2021-03-03 op "USAGE: %s [-fn] [-c config] | [-6h] [-d certs-dir] [-H host]\n"
323 aa372875 2021-02-10 op " [-p port] [-x cgi] [dir]\n",
328 376a5407 2021-02-23 op logger_init(void)
332 376a5407 2021-02-23 op if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, p) == -1)
333 376a5407 2021-02-23 op err(1, "socketpair");
335 376a5407 2021-02-23 op switch (fork()) {
337 376a5407 2021-02-23 op err(1, "fork");
339 bc99d868 2021-03-19 op signal(SIGHUP, SIG_IGN);
341 376a5407 2021-02-23 op setproctitle("logger");
342 bc99d868 2021-03-19 op imsg_init(&logibuf, p[1]);
344 bc99d868 2021-03-19 op _exit(logger_main(p[1], &logibuf));
347 bc99d868 2021-03-19 op imsg_init(&logibuf, p[0]);
353 bc99d868 2021-03-19 op serve(int argc, char **argv, struct imsgbuf *ibuf)
355 2c3e53da 2021-03-03 op char path[PATH_MAX];
358 2c3e53da 2021-03-03 op if (config_path == NULL) {
359 d672b8fb 2021-02-03 op if (hostname == NULL)
360 d672b8fb 2021-02-03 op hostname = "localhost";
361 d672b8fb 2021-02-03 op if (certs_dir == NULL)
362 d672b8fb 2021-02-03 op certs_dir = data_dir();
363 d672b8fb 2021-02-03 op load_local_cert(hostname, certs_dir);
365 d672b8fb 2021-02-03 op hosts[0].domain = "*";
366 d672b8fb 2021-02-03 op hosts[0].locations[0].auto_index = 1;
367 d672b8fb 2021-02-03 op hosts[0].locations[0].match = "*";
369 d672b8fb 2021-02-03 op switch (argc) {
371 d672b8fb 2021-02-03 op hosts[0].dir = getcwd(path, sizeof(path));
374 d672b8fb 2021-02-03 op hosts[0].dir = absolutify_path(argv[0]);
377 d672b8fb 2021-02-03 op usage(getprogname());
381 3abf91b0 2021-02-07 op log_notice(NULL, "serving %s on port %d", hosts[0].dir, conf.port);
384 d672b8fb 2021-02-03 op /* setup tls before dropping privileges: we don't want user
385 d672b8fb 2021-02-03 op * to put private certs inside the chroot. */
388 2c3e53da 2021-03-03 op for (i = 0; i < conf.prefork; ++i) {
389 2c3e53da 2021-03-03 op if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC,
390 2c3e53da 2021-03-03 op PF_UNSPEC, p) == -1)
391 2c3e53da 2021-03-03 op fatal("socketpair: %s", strerror(errno));
393 2c3e53da 2021-03-03 op switch (fork()) {
395 2c3e53da 2021-03-03 op fatal("fork: %s", strerror(errno));
396 2c3e53da 2021-03-03 op case 0: /* child */
398 bc99d868 2021-03-19 op imsg_init(&exibuf, p[1]);
399 2c3e53da 2021-03-03 op setproctitle("server");
400 bc99d868 2021-03-19 op _exit(listener_main(&exibuf));
403 bc99d868 2021-03-19 op imsg_init(&servibuf[i], p[0]);
407 2c3e53da 2021-03-03 op setproctitle("executor");
409 bc99d868 2021-03-19 op _exit(executor_main(ibuf));
413 8d6ae384 2021-01-24 op main(int argc, char **argv)
415 d632468d 2021-03-20 op struct imsgbuf exibuf;
416 2c3e53da 2021-03-03 op int ch, conftest = 0, configless = 0;
417 ca21e100 2021-02-04 op int old_ipv6, old_port;
419 501e489c 2021-01-24 op init_config();
421 8904fa0e 2021-01-27 op while ((ch = getopt(argc, argv, "6c:d:fH:hnp:vx:")) != -1) {
422 3e4749f7 2020-10-02 op switch (ch) {
424 15902770 2021-01-15 op conf.ipv6 = 1;
425 8443bff7 2021-01-25 op configless = 1;
429 ca21e100 2021-02-04 op config_path = absolutify_path(optarg);
433 8443bff7 2021-01-25 op certs_dir = optarg;
434 8443bff7 2021-01-25 op configless = 1;
438 3abf91b0 2021-02-07 op conf.foreground = 1;
442 8443bff7 2021-01-25 op hostname = optarg;
443 8443bff7 2021-01-25 op configless = 1;
447 3e4749f7 2020-10-02 op usage(*argv);
451 15902770 2021-01-15 op conftest = 1;
455 15902770 2021-01-15 op conf.port = parse_portno(optarg);
456 8443bff7 2021-01-25 op configless = 1;
460 3abf91b0 2021-02-07 op conf.verbose++;
464 15902770 2021-01-15 op /* drop the starting / (if any) */
465 15902770 2021-01-15 op if (*optarg == '/')
467 15902770 2021-01-15 op hosts[0].cgi = optarg;
468 8443bff7 2021-01-25 op configless = 1;
472 3e4749f7 2020-10-02 op usage(*argv);
476 8443bff7 2021-01-25 op argc -= optind;
477 8443bff7 2021-01-25 op argv += optind;
479 d672b8fb 2021-02-03 op if (config_path == NULL) {
480 72bbed91 2021-01-27 op configless = 1;
481 3abf91b0 2021-02-07 op conf.foreground = 1;
482 2c3e53da 2021-03-03 op conf.prefork = 1;
483 3abf91b0 2021-02-07 op conf.verbose++;
486 d672b8fb 2021-02-03 op if (config_path != NULL && (argc > 0 || configless))
487 d672b8fb 2021-02-03 op err(1, "can't specify options in config mode.");
489 132cae8c 2021-01-18 op if (conftest) {
490 d672b8fb 2021-02-03 op parse_conf(config_path);
491 132cae8c 2021-01-18 op puts("config OK");
495 4a28dd01 2020-12-28 op signal(SIGPIPE, SIG_IGN);
496 4a28dd01 2020-12-28 op signal(SIGCHLD, SIG_IGN);
498 3abf91b0 2021-02-07 op if (!conf.foreground && !configless) {
499 0170ba02 2021-01-17 op if (daemon(1, 1) == -1)
500 d278a0c3 2021-02-23 op err(1, "daemon");
503 d672b8fb 2021-02-03 op if (config_path != NULL)
504 d672b8fb 2021-02-03 op parse_conf(config_path);
506 d278a0c3 2021-02-23 op logger_init();
508 d672b8fb 2021-02-03 op sock4 = make_socket(conf.port, AF_INET);
510 d672b8fb 2021-02-03 op if (conf.ipv6)
511 d672b8fb 2021-02-03 op sock6 = make_socket(conf.port, AF_INET6);
513 bc99d868 2021-03-19 op if (configless) {
514 bc99d868 2021-03-19 op serve(argc, argv, NULL);
515 bc99d868 2021-03-19 op imsg_compose(&logibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
516 bc99d868 2021-03-19 op imsg_flush(&logibuf);
521 b9c9123b 2021-03-20 op /* Linux seems to call the event handlers even when we're
522 8e09ee1d 2021-03-20 op * doing a sigwait. These dummy handlers is here to avoid
523 b9c9123b 2021-03-20 op * being terminated on SIGHUP, SIGTERM or SIGINFO. */
524 b9c9123b 2021-03-20 op signal(SIGHUP, dummy_handler);
525 b9c9123b 2021-03-20 op signal(SIGINT, dummy_handler);
526 b9c9123b 2021-03-20 op signal(SIGTERM, dummy_handler);
528 ca21e100 2021-02-04 op /* wait a sighup and reload the daemon */
532 bc99d868 2021-03-19 op if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC,
533 bc99d868 2021-03-19 op PF_UNSPEC, p) == -1)
534 bc99d868 2021-03-19 op fatal("socketpair: %s", strerror(errno));
536 ca21e100 2021-02-04 op switch (fork()) {
538 ca21e100 2021-02-04 op fatal("fork: %s", strerror(errno));
541 bc99d868 2021-03-19 op imsg_init(&exibuf, p[1]);
542 bc99d868 2021-03-19 op _exit(serve(argc, argv, &exibuf));
546 bc99d868 2021-03-19 op imsg_init(&exibuf, p[0]);
548 1d3eb470 2021-03-20 op if (!wait_signal())
551 3abf91b0 2021-02-07 op log_info(NULL, "reloading configuration %s", config_path);
553 bc99d868 2021-03-19 op /* close the executor (it'll close the servers too) */
554 bc99d868 2021-03-19 op imsg_compose(&exibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
555 bc99d868 2021-03-19 op imsg_flush(&exibuf);
558 ca21e100 2021-02-04 op old_ipv6 = conf.ipv6;
559 ca21e100 2021-02-04 op old_port = conf.port;
561 ca21e100 2021-02-04 op free_config();
562 ca21e100 2021-02-04 op init_config();
563 ca21e100 2021-02-04 op parse_conf(config_path);
565 ca21e100 2021-02-04 op if (old_port != conf.port) {
566 ca21e100 2021-02-04 op close(sock4);
567 ca21e100 2021-02-04 op close(sock6);
572 ca21e100 2021-02-04 op if (sock6 != -1 && old_ipv6 != conf.ipv6) {
573 ca21e100 2021-02-04 op close(sock6);
577 ca21e100 2021-02-04 op if (sock4 == -1)
578 ca21e100 2021-02-04 op sock4 = make_socket(conf.port, AF_INET);
579 ca21e100 2021-02-04 op if (sock6 == -1 && conf.ipv6)
580 ca21e100 2021-02-04 op sock6 = make_socket(conf.port, AF_INET6);
583 1d3eb470 2021-03-20 op imsg_compose(&exibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
584 1d3eb470 2021-03-20 op imsg_flush(&exibuf);
586 1d3eb470 2021-03-20 op imsg_compose(&logibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
587 1d3eb470 2021-03-20 op imsg_flush(&logibuf);