diff options
author | 2021-01-19 16:49:10 +0000 | |
---|---|---|
committer | 2021-01-19 16:49:10 +0000 | |
commit | bed1cdeedc8028d2d4a0134981f281ef2eda1e45 (patch) | |
tree | 44658d6de8439f4fddc1769eb22500c12c8f4273 | |
parent | No need for a global slaacd_process; unbreaks -fno-common. (diff) | |
download | wireguard-openbsd-bed1cdeedc8028d2d4a0134981f281ef2eda1e45.tar.xz wireguard-openbsd-bed1cdeedc8028d2d4a0134981f281ef2eda1e45.zip |
Move control_state and ctl_conns to control.c, it's not needed
elsewhere and unbreaks -fno-common.
Inspired by claudio
Problem reported by mortimer
-rw-r--r-- | sbin/slaacd/control.c | 20 | ||||
-rw-r--r-- | sbin/slaacd/control.h | 15 | ||||
-rw-r--r-- | sbin/slaacd/frontend.c | 13 | ||||
-rw-r--r-- | sbin/slaacd/frontend.h | 6 |
4 files changed, 23 insertions, 31 deletions
diff --git a/sbin/slaacd/control.c b/sbin/slaacd/control.c index 48fec3dd71a..faf6cbe4806 100644 --- a/sbin/slaacd/control.c +++ b/sbin/slaacd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.6 2019/03/11 22:53:29 pamela Exp $ */ +/* $OpenBSD: control.c,v 1.7 2021/01/19 16:49:10 florian Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -41,10 +41,23 @@ #define CONTROL_BACKLOG 5 +struct { + struct event ev; + struct event evt; + int fd; +} control_state = {.fd = -1}; + +struct ctl_conn { + TAILQ_ENTRY(ctl_conn) entry; + struct imsgev iev; +}; + struct ctl_conn *control_connbyfd(int); struct ctl_conn *control_connbypid(pid_t); void control_close(int); +TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns = TAILQ_HEAD_INITIALIZER(ctl_conns); + int control_init(char *path) { @@ -89,9 +102,12 @@ control_init(char *path) } int -control_listen(void) +control_listen(int fd) { + if (control_state.fd != -1) + fatalx("%s: received unexpected controlsock", __func__); + control_state.fd = fd; if (listen(control_state.fd, CONTROL_BACKLOG) == -1) { log_warn("%s: listen", __func__); return (-1); diff --git a/sbin/slaacd/control.h b/sbin/slaacd/control.h index c244ed5a5a4..911783f2f00 100644 --- a/sbin/slaacd/control.h +++ b/sbin/slaacd/control.h @@ -1,4 +1,4 @@ -/* $OpenBSD: control.h,v 1.3 2018/08/04 09:36:49 florian Exp $ */ +/* $OpenBSD: control.h,v 1.4 2021/01/19 16:49:10 florian Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -17,19 +17,8 @@ */ #ifndef SMALL -struct { - struct event ev; - struct event evt; - int fd; -} control_state; - -struct ctl_conn { - TAILQ_ENTRY(ctl_conn) entry; - struct imsgev iev; -}; - int control_init(char *); -int control_listen(void); +int control_listen(int); void control_accept(int, short, void *); void control_dispatch_imsg(int, short, void *); int control_imsg_relay(struct imsg *); diff --git a/sbin/slaacd/frontend.c b/sbin/slaacd/frontend.c index f2984bac871..e04ee63e234 100644 --- a/sbin/slaacd/frontend.c +++ b/sbin/slaacd/frontend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.c,v 1.47 2021/01/19 16:48:20 florian Exp $ */ +/* $OpenBSD: frontend.c,v 1.48 2021/01/19 16:49:10 florian Exp $ */ /* * Copyright (c) 2017 Florian Obser <florian@openbsd.org> @@ -143,10 +143,6 @@ frontend(int debug, int verbose) log_init(debug, LOG_DAEMON); log_setverbose(verbose); -#ifndef SMALL - control_state.fd = -1; -#endif /* SMALL */ - if ((pw = getpwnam(SLAACD_USER)) == NULL) fatal("getpwnam"); @@ -357,17 +353,12 @@ frontend_dispatch_main(int fd, short event, void *bula) break; #ifndef SMALL case IMSG_CONTROLFD: - if (control_state.fd != -1) - fatalx("%s: received unexpected controlsock", - __func__); if ((fd = imsg.fd) == -1) fatalx("%s: expected to receive imsg " "control fd but didn't receive any", __func__); - control_state.fd = fd; /* Listen on control socket. */ - TAILQ_INIT(&ctl_conns); - control_listen(); + control_listen(fd); break; case IMSG_CTL_END: control_imsg_relay(&imsg); diff --git a/sbin/slaacd/frontend.h b/sbin/slaacd/frontend.h index 061f5423a60..1b1a4f69054 100644 --- a/sbin/slaacd/frontend.h +++ b/sbin/slaacd/frontend.h @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.h,v 1.3 2017/12/10 10:07:54 florian Exp $ */ +/* $OpenBSD: frontend.h,v 1.4 2021/01/19 16:49:10 florian Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -16,10 +16,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef SMALL -TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns; -#endif /* SMALL */ - void frontend(int, int); void frontend_dispatch_main(int, short, void *); void frontend_dispatch_engine(int, short, void *); |