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

sbin/slaacd/control.c
sbin/slaacd/control.h
sbin/slaacd/frontend.c
sbin/slaacd/frontend.h

index 48fec3d..faf6cbe 100644 (file)
@@ -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>
 
 #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);
index c244ed5..911783f 100644 (file)
@@ -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>
  */
 
 #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 *);
index f2984ba..e04ee63 100644 (file)
@@ -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);
index 061f542..1b1a4f6 100644 (file)
@@ -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>
  * 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 *);