From 7b7b19bcbf98bd77d95e61a7eb8484b6c9e8b30f Mon Sep 17 00:00:00 2001 From: Florian Obser Date: Tue, 19 Jan 2021 16:52:13 +0000 Subject: 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 --- sbin/unwind/control.c | 21 +++++++++++++++++++-- sbin/unwind/control.h | 15 ++------------- sbin/unwind/frontend.c | 10 ++-------- sbin/unwind/frontend.h | 4 +--- 4 files changed, 24 insertions(+), 26 deletions(-) (limited to 'sbin') diff --git a/sbin/unwind/control.c b/sbin/unwind/control.c index b724eaaa37a..0739beeb22b 100644 --- a/sbin/unwind/control.c +++ b/sbin/unwind/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.15 2019/12/18 09:18:27 florian Exp $ */ +/* $OpenBSD: control.c,v 1.16 2021/01/19 16:52:12 florian Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -39,6 +39,19 @@ #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; +}; + +TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns = TAILQ_HEAD_INITIALIZER(ctl_conns); + struct ctl_conn *control_connbyfd(int); struct ctl_conn *control_connbypid(pid_t); void control_close(int); @@ -88,8 +101,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/unwind/control.h b/sbin/unwind/control.h index d5d325bf1d9..b8ec85ebb36 100644 --- a/sbin/unwind/control.h +++ b/sbin/unwind/control.h @@ -1,4 +1,4 @@ -/* $OpenBSD: control.h,v 1.1 2019/01/23 13:11:00 florian Exp $ */ +/* $OpenBSD: control.h,v 1.2 2021/01/19 16:52:12 florian Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -16,19 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -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 fd); void control_accept(int, short, void *); void control_dispatch_imsg(int, short, void *); int control_imsg_relay(struct imsg *); diff --git a/sbin/unwind/frontend.c b/sbin/unwind/frontend.c index 445dc668726..31291194870 100644 --- a/sbin/unwind/frontend.c +++ b/sbin/unwind/frontend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.c,v 1.62 2021/01/19 16:50:50 florian Exp $ */ +/* $OpenBSD: frontend.c,v 1.63 2021/01/19 16:52:12 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -185,7 +185,6 @@ frontend(int debug, int verbose) struct passwd *pw; frontend_conf = config_new_empty(); - control_state.fd = -1; log_init(debug, LOG_DAEMON); log_setverbose(verbose); @@ -433,16 +432,11 @@ frontend_dispatch_main(int fd, short event, void *bula) frontend_startup(); break; 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_TAFD: if ((ta_fd = imsg.fd) != -1) diff --git a/sbin/unwind/frontend.h b/sbin/unwind/frontend.h index 48e5aee028c..5e9c176497c 100644 --- a/sbin/unwind/frontend.h +++ b/sbin/unwind/frontend.h @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.h,v 1.6 2019/11/27 17:09:12 florian Exp $ */ +/* $OpenBSD: frontend.h,v 1.7 2021/01/19 16:52:12 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -17,8 +17,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns; - struct trust_anchor { TAILQ_ENTRY(trust_anchor) entry; char *ta; -- cgit v1.2.3