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

usr.sbin/rad/control.c
usr.sbin/rad/control.h
usr.sbin/rad/frontend.c
usr.sbin/rad/frontend.h

index 8232ca9..d8e0ba2 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: control.c,v 1.5 2019/03/02 03:40:45 pamela Exp $      */
+/*     $OpenBSD: control.c,v 1.6 2021/01/19 16:54:00 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 = -1;
        if (listen(control_state.fd, CONTROL_BACKLOG) == -1) {
                log_warn("%s: listen", __func__);
                return (-1);
index 8ce9b1f..e75b3c1 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: control.h,v 1.2 2018/08/04 09:37:17 florian Exp $     */
+/*     $OpenBSD: control.h,v 1.3 2021/01/19 16:54:00 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 4ef2b13..87a9f18 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: frontend.c,v 1.37 2021/01/19 16:53:27 florian Exp $   */
+/*     $OpenBSD: frontend.c,v 1.38 2021/01/19 16:54:00 florian Exp $   */
 
 /*
  * Copyright (c) 2018 Florian Obser <florian@openbsd.org>
@@ -185,7 +185,6 @@ frontend(int debug, int verbose)
        uint8_t                 *sndcmsgbuf = NULL;
 
        frontend_conf = config_new_empty();
-       control_state.fd = -1;
 
        log_init(debug, LOG_DAEMON);
        log_setverbose(verbose);
@@ -468,17 +467,12 @@ 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;
                default:
                        log_debug("%s: error handling imsg %d", __func__,
index 067ed7e..87296e4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: frontend.h,v 1.3 2018/07/13 08:32:10 florian Exp $    */
+/*     $OpenBSD: frontend.h,v 1.4 2021/01/19 16:54:00 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;
-
 void            frontend(int, int);
 void            frontend_dispatch_main(int, short, void *);
 void            frontend_dispatch_engine(int, short, void *);