Move control_state and ctl_conns to control.c, it's not needed
authorflorian <florian@openbsd.org>
Tue, 19 Jan 2021 16:52:12 +0000 (16:52 +0000)
committerflorian <florian@openbsd.org>
Tue, 19 Jan 2021 16:52:12 +0000 (16:52 +0000)
elsewhere and unbreaks -fno-common.
Inspired by claudio
Problem reported by mortimer

sbin/unwind/control.c
sbin/unwind/control.h
sbin/unwind/frontend.c
sbin/unwind/frontend.h

index b724eaa..0739bee 100644 (file)
@@ -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 <henning@openbsd.org>
 
 #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);
index d5d325b..b8ec85e 100644 (file)
@@ -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 <henning@openbsd.org>
  * 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 *);
index 445dc66..3129119 100644 (file)
@@ -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 <florian@openbsd.org>
@@ -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)
index 48e5aee..5e9c176 100644 (file)
@@ -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 <florian@openbsd.org>
@@ -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;