This is my take on -fno-common fixes.

slaacd, unwind and rad are based on the same template so the fixes
were similar

- remove global $daemon_process, just use a const string for
  setproctitle
- move ctl_conns to control.c and control_state to frontend.c,
  control_state needs to be extern because it's shared between
  frontend.c and control.c. (I see that claudio fixed this differently
  in ospfd)
- give imsgevs unique names by using proc1_to_proc2 variable names
- other fixes unique per daemon


commit 3f23b6c514f2740f3ad559142935474c8063e60c
Author: Florian Obser <flor...@narrans.de>
Date:   Sun Jan 17 19:44:17 2021 +0100

    No need for a global slaacd_process; unbreaks -fno-common.
    Problem reported by mortimer

diff --git sbin/slaacd/engine.c sbin/slaacd/engine.c
index 52380f64439..3911e6b956a 100644
--- sbin/slaacd/engine.c
+++ sbin/slaacd/engine.c
@@ -369,9 +369,8 @@ engine(int debug, int verbose)
        if (chdir("/") == -1)
                fatal("chdir(\"/\")");
 
-       slaacd_process = PROC_ENGINE;
-       setproctitle("%s", log_procnames[slaacd_process]);
-       log_procinit(log_procnames[slaacd_process]);
+       setproctitle("%s", "engine");
+       log_procinit("engine");
 
        if (setgroups(1, &pw->pw_gid) ||
            setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
diff --git sbin/slaacd/frontend.c sbin/slaacd/frontend.c
index ff6539b9ff5..eca8dbea3be 100644
--- sbin/slaacd/frontend.c
+++ sbin/slaacd/frontend.c
@@ -155,9 +155,8 @@ frontend(int debug, int verbose)
        if (chdir("/") == -1)
                fatal("chdir(\"/\")");
 
-       slaacd_process = PROC_FRONTEND;
-       setproctitle("%s", log_procnames[slaacd_process]);
-       log_procinit(log_procnames[slaacd_process]);
+       setproctitle("%s", "frontend");
+       log_procinit("frontend");
 
        if ((ioctlsock = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0)) == -1)
                fatal("socket");
diff --git sbin/slaacd/slaacd.c sbin/slaacd/slaacd.c
index faf4edad31c..7fc9458e7e8 100644
--- sbin/slaacd/slaacd.c
+++ sbin/slaacd/slaacd.c
@@ -54,12 +54,18 @@
 #include "engine.h"
 #include "control.h"
 
+enum slaacd_process {
+       PROC_MAIN,
+       PROC_ENGINE,
+       PROC_FRONTEND
+};
+
 __dead void    usage(void);
 __dead void    main_shutdown(void);
 
 void   main_sig_handler(int, short, void *);
 
-static pid_t   start_child(int, char *, int, int, int);
+static pid_t   start_child(enum slaacd_process, char *, int, int, int);
 
 void   main_dispatch_frontend(int, short, void *);
 void   main_dispatch_engine(int, short, void *);
@@ -197,9 +203,7 @@ main(int argc, char *argv[])
        frontend_pid = start_child(PROC_FRONTEND, saved_argv0,
            pipe_main2frontend[1], debug, verbose);
 
-       slaacd_process = PROC_MAIN;
-
-       log_procinit(log_procnames[slaacd_process]);
+       log_procinit("main");
 
        if ((routesock = socket(AF_ROUTE, SOCK_RAW | SOCK_CLOEXEC |
            SOCK_NONBLOCK, AF_INET6)) == -1)
@@ -319,7 +323,7 @@ main_shutdown(void)
 }
 
 static pid_t
-start_child(int p, char *argv0, int fd, int debug, int verbose)
+start_child(enum slaacd_process p, char *argv0, int fd, int debug, int verbose)
 {
        char    *argv[7];
        int      argc = 0;
diff --git sbin/slaacd/slaacd.h sbin/slaacd/slaacd.h
index 16b47434b0f..7f14f95dda5 100644
--- sbin/slaacd/slaacd.h
+++ sbin/slaacd/slaacd.h
@@ -31,12 +31,6 @@
 
 #define        IMSG_DATA_SIZE(imsg)    ((imsg).hdr.len - IMSG_HEADER_SIZE)
 
-static const char * const log_procnames[] = {
-       "main",
-       "engine",
-       "frontend"
-};
-
 struct imsgev {
        struct imsgbuf   ibuf;
        void            (*handler)(int, short, void *);
@@ -84,12 +78,6 @@ enum imsg_type {
        IMSG_DUP_ADDRESS,
 };
 
-enum {
-       PROC_MAIN,
-       PROC_ENGINE,
-       PROC_FRONTEND
-} slaacd_process;
-
 enum rpref {
        LOW,
        MEDIUM,

commit 721a0aea760c19e47df05d9a6a9f1e68e557ca34
Author: Florian Obser <flor...@narrans.de>
Date:   Sun Jan 17 19:54:17 2021 +0100

    There is only one ctl_conns; unbreaks -fno-common.
    Problem reported by mortimer

diff --git sbin/slaacd/control.c sbin/slaacd/control.c
index 48fec3dd71a..ea6c0c27d07 100644
--- sbin/slaacd/control.c
+++ sbin/slaacd/control.c
@@ -41,6 +41,12 @@
 
 #define        CONTROL_BACKLOG 5
 
+struct ctl_conn {
+       TAILQ_ENTRY(ctl_conn)   entry;
+       struct imsgev           iev;
+};
+TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns;
+
 struct ctl_conn        *control_connbyfd(int);
 struct ctl_conn        *control_connbypid(pid_t);
 void            control_close(int);
@@ -91,7 +97,7 @@ control_init(char *path)
 int
 control_listen(void)
 {
-
+       TAILQ_INIT(&ctl_conns);
        if (listen(control_state.fd, CONTROL_BACKLOG) == -1) {
                log_warn("%s: listen", __func__);
                return (-1);
diff --git sbin/slaacd/control.h sbin/slaacd/control.h
index c244ed5a5a4..8674814e758 100644
--- sbin/slaacd/control.h
+++ sbin/slaacd/control.h
@@ -17,17 +17,14 @@
  */
 
 #ifndef        SMALL
-struct {
+struct control_state {
        struct event    ev;
        struct event    evt;
        int             fd;
-} control_state;
-
-struct ctl_conn {
-       TAILQ_ENTRY(ctl_conn)   entry;
-       struct imsgev           iev;
 };
 
+extern struct control_state    control_state;
+
 int    control_init(char *);
 int    control_listen(void);
 void   control_accept(int, short, void *);
diff --git sbin/slaacd/frontend.c sbin/slaacd/frontend.c
index eca8dbea3be..f0947db7f2f 100644
--- sbin/slaacd/frontend.c
+++ sbin/slaacd/frontend.c
@@ -96,8 +96,9 @@ void           unref_icmp6ev(struct iface *);
 void            set_icmp6sock(int, int);
 void            send_solicitation(uint32_t);
 #ifndef        SMALL
-void            update_autoconf_addresses(uint32_t, char*);
-const char     *flags_to_str(int);
+void                    update_autoconf_addresses(uint32_t, char*);
+const char             *flags_to_str(int);
+struct control_state    control_state;
 #endif /* SMALL */
 
 LIST_HEAD(, iface)              interfaces;
@@ -366,7 +367,6 @@ frontend_dispatch_main(int fd, short event, void *bula)
                                    __func__);
                        control_state.fd = fd;
                        /* Listen on control socket. */
-                       TAILQ_INIT(&ctl_conns);
                        control_listen();
                        break;
                case IMSG_CTL_END:
diff --git sbin/slaacd/frontend.h sbin/slaacd/frontend.h
index 061f5423a60..e9acccd6eb8 100644
--- sbin/slaacd/frontend.h
+++ sbin/slaacd/frontend.h
@@ -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 *);

commit 15d6dc9e859fe782b09969c7416d663b83e222c1
Author: Florian Obser <flor...@narrans.de>
Date:   Mon Jan 18 06:56:40 2021 +0100

    Use per process unique names for imsgevs; unbreaks -fno-common.
    Problem reported by mortimer

diff --git sbin/slaacd/engine.c sbin/slaacd/engine.c
index 3911e6b956a..981baf51495 100644
--- sbin/slaacd/engine.c
+++ sbin/slaacd/engine.c
@@ -329,8 +329,8 @@ int                  engine_imsg_compose_main(int, pid_t, 
void *, uint16_t);
 uint32_t                real_lifetime(struct timespec *, uint32_t);
 void                    merge_dad_couters(struct radv *, struct radv *);
 
-struct imsgev          *iev_frontend;
-struct imsgev          *iev_main;
+struct imsgev          *iev_engine_to_frontend;
+struct imsgev          *iev_engine_to_main;
 int64_t                         proposal_id;
 
 uint32_t                desync_factor;
@@ -391,17 +391,18 @@ engine(int debug, int verbose)
        signal(SIGHUP, SIG_IGN);
 
        /* Setup pipe and event handler to the main process. */
-       if ((iev_main = malloc(sizeof(struct imsgev))) == NULL)
+       if ((iev_engine_to_main = malloc(sizeof(struct imsgev))) == NULL)
                fatal(NULL);
 
-       imsg_init(&iev_main->ibuf, 3);
-       iev_main->handler = engine_dispatch_main;
+       imsg_init(&iev_engine_to_main->ibuf, 3);
+       iev_engine_to_main->handler = engine_dispatch_main;
 
        /* Setup event handlers. */
-       iev_main->events = EV_READ;
-       event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events,
-           iev_main->handler, iev_main);
-       event_add(&iev_main->ev, NULL);
+       iev_engine_to_main->events = EV_READ;
+       event_set(&iev_engine_to_main->ev, iev_engine_to_main->ibuf.fd,
+           iev_engine_to_main->events, iev_engine_to_main->handler,
+           iev_engine_to_main);
+       event_add(&iev_engine_to_main->ev, NULL);
 
        LIST_INIT(&slaacd_interfaces);
 
@@ -416,13 +417,13 @@ __dead void
 engine_shutdown(void)
 {
        /* Close pipes. */
-       msgbuf_clear(&iev_frontend->ibuf.w);
-       close(iev_frontend->ibuf.fd);
-       msgbuf_clear(&iev_main->ibuf.w);
-       close(iev_main->ibuf.fd);
+       msgbuf_clear(&iev_engine_to_frontend->ibuf.w);
+       close(iev_engine_to_frontend->ibuf.fd);
+       msgbuf_clear(&iev_engine_to_main->ibuf.w);
+       close(iev_engine_to_main->ibuf.fd);
 
-       free(iev_frontend);
-       free(iev_main);
+       free(iev_engine_to_frontend);
+       free(iev_engine_to_main);
 
        log_info("engine exiting");
        exit(0);
@@ -432,7 +433,7 @@ int
 engine_imsg_compose_frontend(int type, pid_t pid, void *data,
     uint16_t datalen)
 {
-       return (imsg_compose_event(iev_frontend, type, 0, pid, -1,
+       return (imsg_compose_event(iev_engine_to_frontend, type, 0, pid, -1,
            data, datalen));
 }
 
@@ -440,7 +441,7 @@ int
 engine_imsg_compose_main(int type, pid_t pid, void *data,
     uint16_t datalen)
 {
-       return (imsg_compose_event(iev_main, type, 0, pid, -1,
+       return (imsg_compose_event(iev_engine_to_main, type, 0, pid, -1,
            data, datalen));
 }
 
@@ -660,7 +661,7 @@ engine_dispatch_main(int fd, short event, void *bula)
                         * Setup pipe and event handler to the frontend
                         * process.
                         */
-                       if (iev_frontend)
+                       if (iev_engine_to_frontend)
                                fatalx("%s: received unexpected imsg fd "
                                    "to engine", __func__);
 
@@ -668,18 +669,21 @@ engine_dispatch_main(int fd, short event, void *bula)
                                fatalx("%s: expected to receive imsg fd to "
                                   "engine but didn't receive any", __func__);
 
-                       iev_frontend = malloc(sizeof(struct imsgev));
-                       if (iev_frontend == NULL)
+                       iev_engine_to_frontend = malloc(sizeof(struct imsgev));
+                       if (iev_engine_to_frontend == NULL)
                                fatal(NULL);
 
-                       imsg_init(&iev_frontend->ibuf, fd);
-                       iev_frontend->handler = engine_dispatch_frontend;
-                       iev_frontend->events = EV_READ;
-
-                       event_set(&iev_frontend->ev, iev_frontend->ibuf.fd,
-                       iev_frontend->events, iev_frontend->handler,
-                           iev_frontend);
-                       event_add(&iev_frontend->ev, NULL);
+                       imsg_init(&iev_engine_to_frontend->ibuf, fd);
+                       iev_engine_to_frontend->handler =
+                           engine_dispatch_frontend;
+                       iev_engine_to_frontend->events = EV_READ;
+
+                       event_set(&iev_engine_to_frontend->ev,
+                           iev_engine_to_frontend->ibuf.fd,
+                           iev_engine_to_frontend->events,
+                           iev_engine_to_frontend->handler,
+                           iev_engine_to_frontend);
+                       event_add(&iev_engine_to_frontend->ev, NULL);
 
                        if (pledge("stdio", NULL) == -1)
                                fatal("pledge");
diff --git sbin/slaacd/frontend.c sbin/slaacd/frontend.c
index f0947db7f2f..4bfea679ae8 100644
--- sbin/slaacd/frontend.c
+++ sbin/slaacd/frontend.c
@@ -102,8 +102,8 @@ struct control_state         control_state;
 #endif /* SMALL */
 
 LIST_HEAD(, iface)              interfaces;
-struct imsgev                  *iev_main;
-struct imsgev                  *iev_engine;
+struct imsgev                  *iev_frontend_to_main;
+struct imsgev                  *iev_frontend_to_engine;
 struct event                    ev_route;
 struct msghdr                   sndmhdr;
 struct iovec                    sndiov[4];
@@ -181,14 +181,15 @@ frontend(int debug, int verbose)
        signal(SIGHUP, SIG_IGN);
 
        /* Setup pipe and event handler to the parent process. */
-       if ((iev_main = malloc(sizeof(struct imsgev))) == NULL)
+       if ((iev_frontend_to_main = malloc(sizeof(struct imsgev))) == NULL)
                fatal(NULL);
-       imsg_init(&iev_main->ibuf, 3);
-       iev_main->handler = frontend_dispatch_main;
-       iev_main->events = EV_READ;
-       event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events,
-           iev_main->handler, iev_main);
-       event_add(&iev_main->ev, NULL);
+       imsg_init(&iev_frontend_to_main->ibuf, 3);
+       iev_frontend_to_main->handler = frontend_dispatch_main;
+       iev_frontend_to_main->events = EV_READ;
+       event_set(&iev_frontend_to_main->ev, iev_frontend_to_main->ibuf.fd,
+           iev_frontend_to_main->events, iev_frontend_to_main->handler,
+           iev_frontend_to_main);
+       event_add(&iev_frontend_to_main->ev, NULL);
 
        sndcmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
            CMSG_SPACE(sizeof(int));
@@ -249,15 +250,15 @@ __dead void
 frontend_shutdown(void)
 {
        /* Close pipes. */
-       msgbuf_write(&iev_engine->ibuf.w);
-       msgbuf_clear(&iev_engine->ibuf.w);
-       close(iev_engine->ibuf.fd);
-       msgbuf_write(&iev_main->ibuf.w);
-       msgbuf_clear(&iev_main->ibuf.w);
-       close(iev_main->ibuf.fd);
+       msgbuf_write(&iev_frontend_to_engine->ibuf.w);
+       msgbuf_clear(&iev_frontend_to_engine->ibuf.w);
+       close(iev_frontend_to_engine->ibuf.fd);
+       msgbuf_write(&iev_frontend_to_main->ibuf.w);
+       msgbuf_clear(&iev_frontend_to_main->ibuf.w);
+       close(iev_frontend_to_main->ibuf.fd);
 
-       free(iev_engine);
-       free(iev_main);
+       free(iev_frontend_to_engine);
+       free(iev_frontend_to_main);
 
        log_info("frontend exiting");
        exit(0);
@@ -267,16 +268,16 @@ int
 frontend_imsg_compose_main(int type, pid_t pid, void *data,
     uint16_t datalen)
 {
-       return (imsg_compose_event(iev_main, type, 0, pid, -1, data,
-           datalen));
+       return (imsg_compose_event(iev_frontend_to_main, type, 0, pid, -1,
+           data, datalen));
 }
 
 int
 frontend_imsg_compose_engine(int type, uint32_t peerid, pid_t pid,
     void *data, uint16_t datalen)
 {
-       return (imsg_compose_event(iev_engine, type, peerid, pid, -1,
-           data, datalen));
+       return (imsg_compose_event(iev_frontend_to_engine, type, peerid, pid,
+           -1, data, datalen));
 }
 
 void
@@ -313,7 +314,7 @@ frontend_dispatch_main(int fd, short event, void *bula)
                         * Setup pipe and event handler to the engine
                         * process.
                         */
-                       if (iev_engine)
+                       if (iev_frontend_to_engine)
                                fatalx("%s: received unexpected imsg fd "
                                    "to frontend", __func__);
 
@@ -322,17 +323,21 @@ frontend_dispatch_main(int fd, short event, void *bula)
                                   "frontend but didn't receive any",
                                   __func__);
 
-                       iev_engine = malloc(sizeof(struct imsgev));
-                       if (iev_engine == NULL)
+                       iev_frontend_to_engine = malloc(sizeof(struct imsgev));
+                       if (iev_frontend_to_engine == NULL)
                                fatal(NULL);
 
-                       imsg_init(&iev_engine->ibuf, fd);
-                       iev_engine->handler = frontend_dispatch_engine;
-                       iev_engine->events = EV_READ;
-
-                       event_set(&iev_engine->ev, iev_engine->ibuf.fd,
-                       iev_engine->events, iev_engine->handler, iev_engine);
-                       event_add(&iev_engine->ev, NULL);
+                       imsg_init(&iev_frontend_to_engine->ibuf, fd);
+                       iev_frontend_to_engine->handler =
+                           frontend_dispatch_engine;
+                       iev_frontend_to_engine->events = EV_READ;
+
+                       event_set(&iev_frontend_to_engine->ev,
+                           iev_frontend_to_engine->ibuf.fd,
+                           iev_frontend_to_engine->events,
+                           iev_frontend_to_engine->handler,
+                           iev_frontend_to_engine);
+                       event_add(&iev_frontend_to_engine->ev, NULL);
                        break;
                case IMSG_ICMP6SOCK:
                        if ((icmp6sock = imsg.fd) == -1)
diff --git sbin/slaacd/slaacd.c sbin/slaacd/slaacd.c
index 7fc9458e7e8..e566b6bdf17 100644
--- sbin/slaacd/slaacd.c
+++ sbin/slaacd/slaacd.c
@@ -84,8 +84,8 @@ static int    main_imsg_send_ipc_sockets(struct imsgbuf *, 
struct imsgbuf *);
 int            main_imsg_compose_frontend(int, int, void *, uint16_t);
 int            main_imsg_compose_engine(int, pid_t, void *, uint16_t);
 
-struct imsgev          *iev_frontend;
-struct imsgev          *iev_engine;
+struct imsgev          *iev_main_to_frontend;
+struct imsgev          *iev_main_to_engine;
 
 pid_t   frontend_pid;
 pid_t   engine_pid;
@@ -222,26 +222,29 @@ main(int argc, char *argv[])
 
        /* Setup pipes to children. */
 
-       if ((iev_frontend = malloc(sizeof(struct imsgev))) == NULL ||
-           (iev_engine = malloc(sizeof(struct imsgev))) == NULL)
+       if ((iev_main_to_frontend = malloc(sizeof(struct imsgev))) == NULL ||
+           (iev_main_to_engine = malloc(sizeof(struct imsgev))) == NULL)
                fatal(NULL);
-       imsg_init(&iev_frontend->ibuf, pipe_main2frontend[0]);
-       iev_frontend->handler = main_dispatch_frontend;
-       imsg_init(&iev_engine->ibuf, pipe_main2engine[0]);
-       iev_engine->handler = main_dispatch_engine;
+       imsg_init(&iev_main_to_frontend->ibuf, pipe_main2frontend[0]);
+       iev_main_to_frontend->handler = main_dispatch_frontend;
+       imsg_init(&iev_main_to_engine->ibuf, pipe_main2engine[0]);
+       iev_main_to_engine->handler = main_dispatch_engine;
 
        /* Setup event handlers for pipes to engine & frontend. */
-       iev_frontend->events = EV_READ;
-       event_set(&iev_frontend->ev, iev_frontend->ibuf.fd,
-           iev_frontend->events, iev_frontend->handler, iev_frontend);
-       event_add(&iev_frontend->ev, NULL);
-
-       iev_engine->events = EV_READ;
-       event_set(&iev_engine->ev, iev_engine->ibuf.fd, iev_engine->events,
-           iev_engine->handler, iev_engine);
-       event_add(&iev_engine->ev, NULL);
-
-       if (main_imsg_send_ipc_sockets(&iev_frontend->ibuf, &iev_engine->ibuf))
+       iev_main_to_frontend->events = EV_READ;
+       event_set(&iev_main_to_frontend->ev, iev_main_to_frontend->ibuf.fd,
+           iev_main_to_frontend->events, iev_main_to_frontend->handler,
+           iev_main_to_frontend);
+       event_add(&iev_main_to_frontend->ev, NULL);
+
+       iev_main_to_engine->events = EV_READ;
+       event_set(&iev_main_to_engine->ev, iev_main_to_engine->ibuf.fd,
+           iev_main_to_engine->events, iev_main_to_engine->handler,
+           iev_main_to_engine);
+       event_add(&iev_main_to_engine->ev, NULL);
+
+       if (main_imsg_send_ipc_sockets(&iev_main_to_frontend->ibuf,
+           &iev_main_to_engine->ibuf))
                fatal("could not establish imsg links");
 
        if ((ioctl_sock = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0)) == -1)
@@ -298,10 +301,10 @@ main_shutdown(void)
        int      status;
 
        /* Close pipes. */
-       msgbuf_clear(&iev_frontend->ibuf.w);
-       close(iev_frontend->ibuf.fd);
-       msgbuf_clear(&iev_engine->ibuf.w);
-       close(iev_engine->ibuf.fd);
+       msgbuf_clear(&iev_main_to_frontend->ibuf.w);
+       close(iev_main_to_frontend->ibuf.fd);
+       msgbuf_clear(&iev_main_to_engine->ibuf.w);
+       close(iev_main_to_engine->ibuf.fd);
 
        log_debug("waiting for children to terminate");
        do {
@@ -315,8 +318,8 @@ main_shutdown(void)
                            "frontend", WTERMSIG(status));
        } while (pid != -1 || (pid == -1 && errno == EINTR));
 
-       free(iev_frontend);
-       free(iev_engine);
+       free(iev_main_to_frontend);
+       free(iev_main_to_engine);
 
        log_info("terminating");
        exit(0);
@@ -570,9 +573,9 @@ main_dispatch_engine(int fd, short event, void *bula)
 int
 main_imsg_compose_frontend(int type, int fd, void *data, uint16_t datalen)
 {
-       if (iev_frontend)
-               return (imsg_compose_event(iev_frontend, type, 0, 0, fd, data,
-                   datalen));
+       if (iev_main_to_frontend)
+               return (imsg_compose_event(iev_main_to_frontend, type, 0, 0,
+                   fd, data, datalen));
        else
                return (-1);
 }
@@ -580,9 +583,9 @@ main_imsg_compose_frontend(int type, int fd, void *data, 
uint16_t datalen)
 int
 main_imsg_compose_engine(int type, pid_t pid, void *data, uint16_t datalen)
 {
-       if (iev_engine)
-               return(imsg_compose_event(iev_engine, type, 0, pid, -1, data,
-                   datalen));
+       if (iev_main_to_engine)
+               return(imsg_compose_event(iev_main_to_engine, type, 0, pid,
+                   -1, data, datalen));
        else
                return (-1);
 }
commit bdadc021ec2f443c76fea2c6449a9b29a1d583a8
Author: Florian Obser <flor...@narrans.de>
Date:   Mon Jan 18 07:03:30 2021 +0100

    No need for a global uw_process; unbreaks -fno-common.
    Problem reported by mortimer

diff --git sbin/unwind/frontend.c sbin/unwind/frontend.c
index 9ef3c6b96a5..00ed5cbd0fd 100644
--- sbin/unwind/frontend.c
+++ sbin/unwind/frontend.c
@@ -198,9 +198,8 @@ frontend(int debug, int verbose)
        if (chdir("/") == -1)
                fatal("chdir(\"/\")");
 
-       uw_process = PROC_FRONTEND;
-       setproctitle("%s", log_procnames[uw_process]);
-       log_procinit(log_procnames[uw_process]);
+       setproctitle("%s", "frontend");
+       log_procinit("frontend");
 
        if (setgroups(1, &pw->pw_gid) ||
            setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
diff --git sbin/unwind/resolver.c sbin/unwind/resolver.c
index e2b5abb35ea..eadacc177b8 100644
--- sbin/unwind/resolver.c
+++ sbin/unwind/resolver.c
@@ -355,9 +355,8 @@ resolver(int debug, int verbose)
        if ((pw = getpwnam(UNWIND_USER)) == NULL)
                fatal("getpwnam");
 
-       uw_process = PROC_RESOLVER;
-       setproctitle("%s", log_procnames[uw_process]);
-       log_procinit(log_procnames[uw_process]);
+       setproctitle("%s", "resolver");
+       log_procinit("resolver");
 
        if (setgroups(1, &pw->pw_gid) ||
            setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
diff --git sbin/unwind/unwind.c sbin/unwind/unwind.c
index c161401cded..a78b84c0e9f 100644
--- sbin/unwind/unwind.c
+++ sbin/unwind/unwind.c
@@ -50,12 +50,18 @@
 
 #define        TRUST_ANCHOR_FILE       "/var/db/unwind.key"
 
+enum uw_process {
+       PROC_MAIN,
+       PROC_RESOLVER,
+       PROC_FRONTEND,
+};
+
 __dead void    usage(void);
 __dead void    main_shutdown(void);
 
 void           main_sig_handler(int, short, void *);
 
-static pid_t   start_child(int, char *, int, int, int);
+static pid_t   start_child(enum uw_process, char *, int, int, int);
 
 void           main_dispatch_frontend(int, short, void *);
 void           main_dispatch_resolver(int, short, void *);
@@ -218,8 +224,7 @@ main(int argc, char *argv[])
            pipe_main2frontend[1], debug, cmd_opts & (OPT_VERBOSE |
            OPT_VERBOSE2 | OPT_VERBOSE3));
 
-       uw_process = PROC_MAIN;
-       log_procinit(log_procnames[uw_process]);
+       log_procinit("main");
 
        event_init();
 
@@ -336,7 +341,7 @@ main_shutdown(void)
 }
 
 static pid_t
-start_child(int p, char *argv0, int fd, int debug, int verbose)
+start_child(enum uw_process p, char *argv0, int fd, int debug, int verbose)
 {
        char    *argv[7];
        int      argc = 0;
diff --git sbin/unwind/unwind.h sbin/unwind/unwind.h
index 910378f3faf..41acf8448ed 100644
--- sbin/unwind/unwind.h
+++ sbin/unwind/unwind.h
@@ -44,18 +44,6 @@
 
 #define        IMSG_DATA_SIZE(imsg)    ((imsg).hdr.len - IMSG_HEADER_SIZE)
 
-enum {
-       PROC_MAIN,
-       PROC_RESOLVER,
-       PROC_FRONTEND,
-} uw_process;
-
-static const char * const log_procnames[] = {
-       "main",
-       "resolver",
-       "frontend",
-};
-
 enum uw_resolver_type {
        UW_RES_RECURSOR,
        UW_RES_DHCP,

commit c7098c4d4b248f96a6bac989480929573419c861
Author: Florian Obser <flor...@narrans.de>
Date:   Mon Jan 18 07:08:55 2021 +0100

    There is only one ctl_conns; unbreaks -fno-common.
    Problem reported by mortimer

diff --git sbin/unwind/control.c sbin/unwind/control.c
index b724eaaa37a..db1b045fd4c 100644
--- sbin/unwind/control.c
+++ sbin/unwind/control.c
@@ -39,6 +39,12 @@
 
 #define        CONTROL_BACKLOG 5
 
+struct ctl_conn {
+       TAILQ_ENTRY(ctl_conn)   entry;
+       struct imsgev           iev;
+};
+TAILQ_HEAD(ctl_conns, ctl_conn)        ctl_conns;
+
 struct ctl_conn        *control_connbyfd(int);
 struct ctl_conn        *control_connbypid(pid_t);
 void            control_close(int);
@@ -90,6 +96,7 @@ control_init(char *path)
 int
 control_listen(void)
 {
+       TAILQ_INIT(&ctl_conns);
        if (listen(control_state.fd, CONTROL_BACKLOG) == -1) {
                log_warn("%s: listen", __func__);
                return (-1);
diff --git sbin/unwind/control.h sbin/unwind/control.h
index d5d325bf1d9..9a9e549c0c1 100644
--- sbin/unwind/control.h
+++ sbin/unwind/control.h
@@ -16,17 +16,14 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-struct {
+struct control_state {
        struct event    ev;
        struct event    evt;
        int             fd;
-} control_state;
-
-struct ctl_conn {
-       TAILQ_ENTRY(ctl_conn)   entry;
-       struct imsgev           iev;
 };
 
+extern struct control_state    control_state;
+
 int    control_init(char *);
 int    control_listen(void);
 void   control_accept(int, short, void *);
diff --git sbin/unwind/frontend.c sbin/unwind/frontend.c
index 00ed5cbd0fd..cb338843824 100644
--- sbin/unwind/frontend.c
+++ sbin/unwind/frontend.c
@@ -147,6 +147,7 @@ int                  bl_cmp(struct bl_node *, struct 
bl_node *);
 void                    free_bl(void);
 int                     pending_query_cnt(void);
 
+struct control_state    control_state;
 struct uw_conf         *frontend_conf;
 struct imsgev          *iev_main;
 struct imsgev          *iev_resolver;
@@ -438,7 +439,6 @@ frontend_dispatch_main(int fd, short event, void *bula)
                                    "fd but didn't receive any", __func__);
                        control_state.fd = fd;
                        /* Listen on control socket. */
-                       TAILQ_INIT(&ctl_conns);
                        control_listen();
                        break;
                case IMSG_TAFD:
diff --git sbin/unwind/frontend.h sbin/unwind/frontend.h
index 48e5aee028c..0daa03bf450 100644
--- sbin/unwind/frontend.h
+++ sbin/unwind/frontend.h
@@ -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;

commit 5c55ebe67c6488a96df447ac5ce28c05e2b2465b
Author: Florian Obser <flor...@narrans.de>
Date:   Mon Jan 18 07:14:14 2021 +0100

    Give the routesock a unique name; unbreaks -fno-common.
    Problem reported by mortimer

diff --git sbin/unwind/frontend.c sbin/unwind/frontend.c
index cb338843824..02df1ab71c9 100644
--- sbin/unwind/frontend.c
+++ sbin/unwind/frontend.c
@@ -152,7 +152,7 @@ struct uw_conf              *frontend_conf;
 struct imsgev          *iev_main;
 struct imsgev          *iev_resolver;
 struct event            ev_route;
-int                     udp4sock = -1, udp6sock = -1, routesock = -1;
+int                     udp4sock = -1, udp6sock = -1, frontend_routesock = -1;
 int                     tcp4sock = -1, tcp6sock = -1;
 int                     ta_fd = -1;
 
@@ -416,14 +416,14 @@ frontend_dispatch_main(int fd, short event, void *bula)
                        evtimer_set(&tcp6ev.pause, accept_paused, &tcp6ev);
                        break;
                case IMSG_ROUTESOCK:
-                       if (routesock != -1)
+                       if (frontend_routesock != -1)
                                fatalx("%s: received unexpected routesock",
                                    __func__);
                        if ((fd = imsg.fd) == -1)
                                fatalx("%s: expected to receive imsg "
                                    "routesocket fd but didn't receive any",
                                    __func__);
-                       routesock = fd;
+                       frontend_routesock = fd;
                        event_set(&ev_route, fd, EV_READ | EV_PERSIST,
                            route_receive, NULL);
                        break;
diff --git sbin/unwind/unwind.c sbin/unwind/unwind.c
index a78b84c0e9f..e4c70595484 100644
--- sbin/unwind/unwind.c
+++ sbin/unwind/unwind.c
@@ -85,7 +85,7 @@ pid_t          resolver_pid;
 
 uint32_t        cmd_opts;
 
-int             routesock;
+int             main_routesock;
 
 void
 main_sig_handler(int sig, short event, void *arg)
@@ -277,10 +277,10 @@ main(int argc, char *argv[])
            &rtfilter, sizeof(rtfilter)) == -1)
                fatal("setsockopt(ROUTE_MSGFILTER)");
 
-       if ((routesock = socket(AF_ROUTE, SOCK_RAW | SOCK_CLOEXEC |
+       if ((main_routesock = socket(AF_ROUTE, SOCK_RAW | SOCK_CLOEXEC |
            SOCK_NONBLOCK, AF_INET6)) == -1)
                fatal("route socket");
-       shutdown(SHUT_RD, routesock);
+       shutdown(SHUT_RD, main_routesock);
 
        if ((ta_fd = open(TRUST_ANCHOR_FILE, O_RDWR | O_CREAT, 0644)) == -1)
                log_warn("%s", TRUST_ANCHOR_FILE);
@@ -868,7 +868,7 @@ solicit_dns_proposals(void)
        iov[iovcnt].iov_base = &rtm;
        iov[iovcnt++].iov_len = sizeof(rtm);
 
-       if (writev(routesock, iov, iovcnt) == -1)
+       if (writev(main_routesock, iov, iovcnt) == -1)
                log_warn("failed to send solicitation");
 }
 

commit 19250a0768065191d34abaf91951559d8f1d585f
Author: Florian Obser <flor...@narrans.de>
Date:   Mon Jan 18 07:20:20 2021 +0100

    Use per process unique names for imsgevs; unbreaks -fno-common.
    Problem reported by mortimer

diff --git sbin/unwind/frontend.c sbin/unwind/frontend.c
index 02df1ab71c9..2f87ca617e3 100644
--- sbin/unwind/frontend.c
+++ sbin/unwind/frontend.c
@@ -149,8 +149,8 @@ int                  pending_query_cnt(void);
 
 struct control_state    control_state;
 struct uw_conf         *frontend_conf;
-struct imsgev          *iev_main;
-struct imsgev          *iev_resolver;
+struct imsgev          *iev_frontend_to_main;
+struct imsgev          *iev_frontend_to_resolver;
 struct event            ev_route;
 int                     udp4sock = -1, udp6sock = -1, frontend_routesock = -1;
 int                     tcp4sock = -1, tcp6sock = -1;
@@ -221,16 +221,17 @@ frontend(int debug, int verbose)
        signal(SIGHUP, SIG_IGN);
 
        /* Setup pipe and event handler to the parent process. */
-       if (iev_main != NULL)
-               fatal("iev_main");
-       if ((iev_main = malloc(sizeof(struct imsgev))) == NULL)
+       if (iev_frontend_to_main != NULL)
+               fatal("iev_frontend_to_main");
+       if ((iev_frontend_to_main = malloc(sizeof(struct imsgev))) == NULL)
                fatal(NULL);
-       imsg_init(&iev_main->ibuf, 3);
-       iev_main->handler = frontend_dispatch_main;
-       iev_main->events = EV_READ;
-       event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events,
-           iev_main->handler, iev_main);
-       event_add(&iev_main->ev, NULL);
+       imsg_init(&iev_frontend_to_main->ibuf, 3);
+       iev_frontend_to_main->handler = frontend_dispatch_main;
+       iev_frontend_to_main->events = EV_READ;
+       event_set(&iev_frontend_to_main->ev, iev_frontend_to_main->ibuf.fd,
+           iev_frontend_to_main->events, iev_frontend_to_main->handler,
+           iev_frontend_to_main);
+       event_add(&iev_frontend_to_main->ev, NULL);
 
        udp4ev.rcviov[0].iov_base = (caddr_t)udp4ev.query;
        udp4ev.rcviov[0].iov_len = sizeof(udp4ev.query);
@@ -262,17 +263,17 @@ __dead void
 frontend_shutdown(void)
 {
        /* Close pipes. */
-       msgbuf_write(&iev_resolver->ibuf.w);
-       msgbuf_clear(&iev_resolver->ibuf.w);
-       close(iev_resolver->ibuf.fd);
-       msgbuf_write(&iev_main->ibuf.w);
-       msgbuf_clear(&iev_main->ibuf.w);
-       close(iev_main->ibuf.fd);
+       msgbuf_write(&iev_frontend_to_resolver->ibuf.w);
+       msgbuf_clear(&iev_frontend_to_resolver->ibuf.w);
+       close(iev_frontend_to_resolver->ibuf.fd);
+       msgbuf_write(&iev_frontend_to_main->ibuf.w);
+       msgbuf_clear(&iev_frontend_to_main->ibuf.w);
+       close(iev_frontend_to_main->ibuf.fd);
 
        config_clear(frontend_conf);
 
-       free(iev_resolver);
-       free(iev_main);
+       free(iev_frontend_to_resolver);
+       free(iev_frontend_to_main);
 
        log_info("frontend exiting");
        exit(0);
@@ -281,15 +282,16 @@ frontend_shutdown(void)
 int
 frontend_imsg_compose_main(int type, pid_t pid, void *data, uint16_t datalen)
 {
-       return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen));
+       return (imsg_compose_event(iev_frontend_to_main, type, 0, pid, -1,
+           data, datalen));
 }
 
 int
 frontend_imsg_compose_resolver(int type, pid_t pid, void *data,
     uint16_t datalen)
 {
-       return (imsg_compose_event(iev_resolver, type, 0, pid, -1, data,
-           datalen));
+       return (imsg_compose_event(iev_frontend_to_resolver, type, 0, pid, -1,
+           data, datalen));
 }
 
 void
@@ -326,7 +328,7 @@ frontend_dispatch_main(int fd, short event, void *bula)
                         * Setup pipe and event handler to the resolver
                         * process.
                         */
-                       if (iev_resolver) {
+                       if (iev_frontend_to_resolver) {
                                fatalx("%s: received unexpected imsg fd "
                                    "to frontend", __func__);
                                break;
@@ -338,20 +340,24 @@ frontend_dispatch_main(int fd, short event, void *bula)
                                break;
                        }
 
-                       if (iev_resolver != NULL)
-                               fatal("iev_resolver");
-                       iev_resolver = malloc(sizeof(struct imsgev));
-                       if (iev_resolver == NULL)
+                       if (iev_frontend_to_resolver != NULL)
+                               fatal("iev_frontend_to_resolver");
+                       iev_frontend_to_resolver =
+                           malloc(sizeof(struct imsgev));
+                       if (iev_frontend_to_resolver == NULL)
                                fatal(NULL);
 
-                       imsg_init(&iev_resolver->ibuf, fd);
-                       iev_resolver->handler = frontend_dispatch_resolver;
-                       iev_resolver->events = EV_READ;
-
-                       event_set(&iev_resolver->ev, iev_resolver->ibuf.fd,
-                           iev_resolver->events, iev_resolver->handler,
-                           iev_resolver);
-                       event_add(&iev_resolver->ev, NULL);
+                       imsg_init(&iev_frontend_to_resolver->ibuf, fd);
+                       iev_frontend_to_resolver->handler =
+                           frontend_dispatch_resolver;
+                       iev_frontend_to_resolver->events = EV_READ;
+
+                       event_set(&iev_frontend_to_resolver->ev,
+                           iev_frontend_to_resolver->ibuf.fd,
+                           iev_frontend_to_resolver->events,
+                           iev_frontend_to_resolver->handler,
+                           iev_frontend_to_resolver);
+                       event_add(&iev_frontend_to_resolver->ev, NULL);
                        break;
                case IMSG_RECONF_CONF:
                case IMSG_RECONF_BLOCKLIST_FILE:
diff --git sbin/unwind/resolver.c sbin/unwind/resolver.c
index eadacc177b8..c87cb4ba426 100644
--- sbin/unwind/resolver.c
+++ sbin/unwind/resolver.c
@@ -197,8 +197,8 @@ int                 *resolvers_to_restart(struct uw_conf *,
 const char             *query_imsg2str(struct query_imsg *);
 
 struct uw_conf                 *resolver_conf;
-struct imsgev                  *iev_frontend;
-struct imsgev                  *iev_main;
+struct imsgev                  *iev_resolver_to_frontend;
+struct imsgev                  *iev_resolver_to_main;
 struct uw_forwarder_head        autoconf_forwarder_list;
 struct uw_resolver             *resolvers[UW_RES_NONE];
 int                             enabled_resolvers[UW_RES_NONE];
@@ -380,17 +380,18 @@ resolver(int debug, int verbose)
        signal(SIGHUP, SIG_IGN);
 
        /* Setup pipe and event handler to the main process. */
-       if ((iev_main = malloc(sizeof(struct imsgev))) == NULL)
+       if ((iev_resolver_to_main = malloc(sizeof(struct imsgev))) == NULL)
                fatal(NULL);
 
-       imsg_init(&iev_main->ibuf, 3);
-       iev_main->handler = resolver_dispatch_main;
+       imsg_init(&iev_resolver_to_main->ibuf, 3);
+       iev_resolver_to_main->handler = resolver_dispatch_main;
 
        /* Setup event handlers. */
-       iev_main->events = EV_READ;
-       event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events,
-           iev_main->handler, iev_main);
-       event_add(&iev_main->ev, NULL);
+       iev_resolver_to_main->events = EV_READ;
+       event_set(&iev_resolver_to_main->ev, iev_resolver_to_main->ibuf.fd,
+           iev_resolver_to_main->events, iev_resolver_to_main->handler,
+           iev_resolver_to_main);
+       event_add(&iev_resolver_to_main->ev, NULL);
 
        evtimer_set(&trust_anchor_timer, trust_anchor_timo, NULL);
        evtimer_set(&decay_timer, decay_latest_histograms, NULL);
@@ -419,15 +420,15 @@ __dead void
 resolver_shutdown(void)
 {
        /* Close pipes. */
-       msgbuf_clear(&iev_frontend->ibuf.w);
-       close(iev_frontend->ibuf.fd);
-       msgbuf_clear(&iev_main->ibuf.w);
-       close(iev_main->ibuf.fd);
+       msgbuf_clear(&iev_resolver_to_frontend->ibuf.w);
+       close(iev_resolver_to_frontend->ibuf.fd);
+       msgbuf_clear(&iev_resolver_to_main->ibuf.w);
+       close(iev_resolver_to_main->ibuf.fd);
 
        config_clear(resolver_conf);
 
-       free(iev_frontend);
-       free(iev_main);
+       free(iev_resolver_to_frontend);
+       free(iev_resolver_to_main);
 
        log_info("resolver exiting");
        exit(0);
@@ -436,14 +437,15 @@ resolver_shutdown(void)
 int
 resolver_imsg_compose_main(int type, pid_t pid, void *data, uint16_t datalen)
 {
-       return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen));
+       return (imsg_compose_event(iev_resolver_to_main, type, 0, pid, -1,
+           data, datalen));
 }
 
 int
 resolver_imsg_compose_frontend(int type, pid_t pid, void *data,
     uint16_t datalen)
 {
-       return (imsg_compose_event(iev_frontend, type, 0, pid, -1,
+       return (imsg_compose_event(iev_resolver_to_frontend, type, 0, pid, -1,
            data, datalen));
 }
 
@@ -608,7 +610,7 @@ resolver_dispatch_main(int fd, short event, void *bula)
                         * Setup pipe and event handler to the frontend
                         * process.
                         */
-                       if (iev_frontend)
+                       if (iev_resolver_to_frontend)
                                fatalx("%s: received unexpected imsg fd "
                                    "to resolver", __func__);
 
@@ -616,18 +618,22 @@ resolver_dispatch_main(int fd, short event, void *bula)
                                fatalx("%s: expected to receive imsg fd to "
                                   "resolver but didn't receive any", __func__);
 
-                       iev_frontend = malloc(sizeof(struct imsgev));
-                       if (iev_frontend == NULL)
+                       iev_resolver_to_frontend =
+                           malloc(sizeof(struct imsgev));
+                       if (iev_resolver_to_frontend == NULL)
                                fatal(NULL);
 
-                       imsg_init(&iev_frontend->ibuf, fd);
-                       iev_frontend->handler = resolver_dispatch_frontend;
-                       iev_frontend->events = EV_READ;
-
-                       event_set(&iev_frontend->ev, iev_frontend->ibuf.fd,
-                       iev_frontend->events, iev_frontend->handler,
-                           iev_frontend);
-                       event_add(&iev_frontend->ev, NULL);
+                       imsg_init(&iev_resolver_to_frontend->ibuf, fd);
+                       iev_resolver_to_frontend->handler =
+                           resolver_dispatch_frontend;
+                       iev_resolver_to_frontend->events = EV_READ;
+
+                       event_set(&iev_resolver_to_frontend->ev,
+                           iev_resolver_to_frontend->ibuf.fd,
+                           iev_resolver_to_frontend->events,
+                           iev_resolver_to_frontend->handler,
+                           iev_resolver_to_frontend);
+                       event_add(&iev_resolver_to_frontend->ev, NULL);
                        break;
 
                case IMSG_STARTUP:
diff --git sbin/unwind/unwind.c sbin/unwind/unwind.c
index e4c70595484..b7c0b47c307 100644
--- sbin/unwind/unwind.c
+++ sbin/unwind/unwind.c
@@ -76,8 +76,8 @@ void          solicit_dns_proposals(void);
 void           send_blocklist_fd(void);
 
 struct uw_conf *main_conf;
-struct imsgev  *iev_frontend;
-struct imsgev  *iev_resolver;
+struct imsgev  *iev_main_to_frontend;
+struct imsgev  *iev_main_to_resolver;
 char           *conffile;
 
 pid_t           frontend_pid;
@@ -239,27 +239,29 @@ main(int argc, char *argv[])
 
        /* Setup pipes to children. */
 
-       if ((iev_frontend = malloc(sizeof(struct imsgev))) == NULL ||
-           (iev_resolver = malloc(sizeof(struct imsgev))) == NULL)
+       if ((iev_main_to_frontend = malloc(sizeof(struct imsgev))) == NULL ||
+           (iev_main_to_resolver = malloc(sizeof(struct imsgev))) == NULL)
                fatal(NULL);
-       imsg_init(&iev_frontend->ibuf, pipe_main2frontend[0]);
-       iev_frontend->handler = main_dispatch_frontend;
-       imsg_init(&iev_resolver->ibuf, pipe_main2resolver[0]);
-       iev_resolver->handler = main_dispatch_resolver;
+       imsg_init(&iev_main_to_frontend->ibuf, pipe_main2frontend[0]);
+       iev_main_to_frontend->handler = main_dispatch_frontend;
+       imsg_init(&iev_main_to_resolver->ibuf, pipe_main2resolver[0]);
+       iev_main_to_resolver->handler = main_dispatch_resolver;
 
        /* Setup event handlers for pipes. */
-       iev_frontend->events = EV_READ;
-       event_set(&iev_frontend->ev, iev_frontend->ibuf.fd,
-           iev_frontend->events, iev_frontend->handler, iev_frontend);
-       event_add(&iev_frontend->ev, NULL);
-
-       iev_resolver->events = EV_READ;
-       event_set(&iev_resolver->ev, iev_resolver->ibuf.fd,
-           iev_resolver->events, iev_resolver->handler, iev_resolver);
-       event_add(&iev_resolver->ev, NULL);
-
-       if (main_imsg_send_ipc_sockets(&iev_frontend->ibuf,
-           &iev_resolver->ibuf))
+       iev_main_to_frontend->events = EV_READ;
+       event_set(&iev_main_to_frontend->ev, iev_main_to_frontend->ibuf.fd,
+           iev_main_to_frontend->events, iev_main_to_frontend->handler,
+           iev_main_to_frontend);
+       event_add(&iev_main_to_frontend->ev, NULL);
+
+       iev_main_to_resolver->events = EV_READ;
+       event_set(&iev_main_to_resolver->ev, iev_main_to_resolver->ibuf.fd,
+           iev_main_to_resolver->events, iev_main_to_resolver->handler,
+           iev_main_to_resolver);
+       event_add(&iev_main_to_resolver->ev, NULL);
+
+       if (main_imsg_send_ipc_sockets(&iev_main_to_frontend->ibuf,
+           &iev_main_to_resolver->ibuf))
                fatal("could not establish imsg links");
 
        open_ports();
@@ -314,10 +316,10 @@ main_shutdown(void)
        int      status;
 
        /* Close pipes. */
-       msgbuf_clear(&iev_frontend->ibuf.w);
-       close(iev_frontend->ibuf.fd);
-       msgbuf_clear(&iev_resolver->ibuf.w);
-       close(iev_resolver->ibuf.fd);
+       msgbuf_clear(&iev_main_to_frontend->ibuf.w);
+       close(iev_main_to_frontend->ibuf.fd);
+       msgbuf_clear(&iev_main_to_resolver->ibuf.w);
+       close(iev_main_to_resolver->ibuf.fd);
 
        config_clear(main_conf);
 
@@ -333,8 +335,8 @@ main_shutdown(void)
                            "frontend", WTERMSIG(status));
        } while (pid != -1 || (pid == -1 && errno == EINTR));
 
-       free(iev_frontend);
-       free(iev_resolver);
+       free(iev_main_to_frontend);
+       free(iev_main_to_resolver);
 
        log_info("terminating");
        exit(0);
@@ -501,24 +503,25 @@ main_dispatch_resolver(int fd, short event, void *bula)
 void
 main_imsg_compose_frontend(int type, pid_t pid, void *data, uint16_t datalen)
 {
-       if (iev_frontend)
-               imsg_compose_event(iev_frontend, type, 0, pid, -1, data,
-                   datalen);
+       if (iev_main_to_frontend)
+               imsg_compose_event(iev_main_to_frontend, type, 0, pid, -1,
+                   data, datalen);
 }
 
 void
 main_imsg_compose_frontend_fd(int type, pid_t pid, int fd)
 {
-       if (iev_frontend)
-               imsg_compose_event(iev_frontend, type, 0, pid, fd, NULL, 0);
+       if (iev_main_to_frontend)
+               imsg_compose_event(iev_main_to_frontend, type, 0, pid, fd,
+                   NULL, 0);
 }
 
 void
 main_imsg_compose_resolver(int type, pid_t pid, void *data, uint16_t datalen)
 {
-       if (iev_resolver)
-               imsg_compose_event(iev_resolver, type, 0, pid, -1, data,
-                   datalen);
+       if (iev_main_to_resolver)
+               imsg_compose_event(iev_main_to_resolver, type, 0, pid, -1,
+                   data, datalen);
 }
 
 void
@@ -632,9 +635,11 @@ main_imsg_send_config(struct uw_conf *xconf)
 int
 main_sendall(enum imsg_type type, void *buf, uint16_t len)
 {
-       if (imsg_compose_event(iev_frontend, type, 0, 0, -1, buf, len) == -1)
+       if (imsg_compose_event(iev_main_to_frontend, type, 0, 0, -1, buf, len)
+           == -1)
                return (-1);
-       if (imsg_compose_event(iev_resolver, type, 0, 0, -1, buf, len) == -1)
+       if (imsg_compose_event(iev_main_to_resolver, type, 0, 0, -1, buf, len)
+           == -1)
                return (-1);
        return (0);
 }

commit 7ba4d76b61fa63058554849de2ff6bc227cc16f6
Author: Florian Obser <flor...@narrans.de>
Date:   Mon Jan 18 16:12:10 2021 +0100

    Prevent more yacc clashes; fixes -fno-common.
    Problem reported by mortimer.

diff --git sbin/unwind/libunbound/util/configyyrename.h 
sbin/unwind/libunbound/util/configyyrename.h
index f529be57727..8c7ff5b5c95 100644
--- sbin/unwind/libunbound/util/configyyrename.h
+++ sbin/unwind/libunbound/util/configyyrename.h
@@ -84,5 +84,11 @@
 #define yyget_leng ub_c_get_leng
 #define yylineno ub_c_lineno
 #define yyget_text ub_c_get_text
+#define yyss    ub_c_ss
+#define yysslim ub_c_sslim
+#define yyssp   ub_c_ssp
+#define yystacksize ub_c_stacksize
+#define yyvs    ub_c_vs
+#define yyvsp   ub_c_vsp
 
 #endif /* UTIL_CONFIGYYRENAME_H */
commit c5ae269d64593b8f4273ebd0e8a08355deda237e
Author: Florian Obser <flor...@narrans.de>
Date:   Mon Jan 18 07:28:48 2021 +0100

    No need for a global rad_process; unbreaks -fno-common.
    Problem reported by mortimer

diff --git usr.sbin/rad/engine.c usr.sbin/rad/engine.c
index 23967f6d2bb..6c1cb0ccb15 100644
--- usr.sbin/rad/engine.c
+++ usr.sbin/rad/engine.c
@@ -105,9 +105,8 @@ engine(int debug, int verbose)
        if (chdir("/") == -1)
                fatal("chdir(\"/\")");
 
-       rad_process = PROC_ENGINE;
-       setproctitle("%s", log_procnames[rad_process]);
-       log_procinit(log_procnames[rad_process]);
+       setproctitle("%s", "engine");
+       log_procinit("engine");
 
        if (setgroups(1, &pw->pw_gid) ||
            setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
diff --git usr.sbin/rad/frontend.c usr.sbin/rad/frontend.c
index e59dc097937..6655ab5d197 100644
--- usr.sbin/rad/frontend.c
+++ usr.sbin/rad/frontend.c
@@ -198,9 +198,8 @@ frontend(int debug, int verbose)
        if (chdir("/") == -1)
                fatal("chdir(\"/\")");
 
-       rad_process = PROC_FRONTEND;
-       setproctitle("%s", log_procnames[rad_process]);
-       log_procinit(log_procnames[rad_process]);
+       setproctitle("%s", "frontend");
+       log_procinit("frontend");
 
        if (setgroups(1, &pw->pw_gid) ||
            setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
diff --git usr.sbin/rad/rad.c usr.sbin/rad/rad.c
index eb59ae15ac1..602c20b3706 100644
--- usr.sbin/rad/rad.c
+++ usr.sbin/rad/rad.c
@@ -52,12 +52,18 @@
 #include "engine.h"
 #include "control.h"
 
+enum rad_process {
+       PROC_MAIN,
+       PROC_ENGINE,
+       PROC_FRONTEND
+};
+
 __dead void    usage(void);
 __dead void    main_shutdown(void);
 
 void   main_sig_handler(int, short, void *);
 
-static pid_t   start_child(int, char *, int, int, int);
+static pid_t   start_child(enum rad_process, char *, int, int, int);
 
 void   main_dispatch_frontend(int, short, void *);
 void   main_dispatch_engine(int, short, void *);
@@ -221,8 +227,7 @@ main(int argc, char *argv[])
        frontend_pid = start_child(PROC_FRONTEND, saved_argv0,
            pipe_main2frontend[1], debug, cmd_opts & OPT_VERBOSE);
 
-       rad_process = PROC_MAIN;
-       log_procinit(log_procnames[rad_process]);
+       log_procinit("main");
 
        event_init();
 
@@ -325,7 +330,7 @@ main_shutdown(void)
 }
 
 static pid_t
-start_child(int p, char *argv0, int fd, int debug, int verbose)
+start_child(enum rad_process p, char *argv0, int fd, int debug, int verbose)
 {
        char    *argv[6];
        int      argc = 0;
diff --git usr.sbin/rad/rad.h usr.sbin/rad/rad.h
index 92368e50022..6e765b5be32 100644
--- usr.sbin/rad/rad.h
+++ usr.sbin/rad/rad.h
@@ -36,18 +36,6 @@
 
 #define        IMSG_DATA_SIZE(imsg)    ((imsg).hdr.len - IMSG_HEADER_SIZE)
 
-enum {
-       PROC_MAIN,
-       PROC_ENGINE,
-       PROC_FRONTEND
-} rad_process;
-
-static const char * const log_procnames[] = {
-       "main",
-       "engine",
-       "frontend",
-};
-
 struct imsgev {
        struct imsgbuf   ibuf;
        void            (*handler)(int, short, void *);

commit e7098094496f4cb967e91605500cda67def3c3c5
Author: Florian Obser <flor...@narrans.de>
Date:   Mon Jan 18 08:41:46 2021 +0100

    There is only one ctl_conns; unbreaks -fno-common.
    Problem reported by mortimer

diff --git usr.sbin/rad/control.c usr.sbin/rad/control.c
index 8232ca96c16..1555b320113 100644
--- usr.sbin/rad/control.c
+++ usr.sbin/rad/control.c
@@ -40,6 +40,13 @@
 
 #define        CONTROL_BACKLOG 5
 
+struct ctl_conn {
+       TAILQ_ENTRY(ctl_conn)   entry;
+       struct imsgev           iev;
+};
+TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns;
+
+struct ctl_conns        ctl_conns;
 struct ctl_conn        *control_connbyfd(int);
 struct ctl_conn        *control_connbypid(pid_t);
 void            control_close(int);
@@ -90,6 +97,7 @@ control_init(char *path)
 int
 control_listen(void)
 {
+       TAILQ_INIT(&ctl_conns);
        if (listen(control_state.fd, CONTROL_BACKLOG) == -1) {
                log_warn("%s: listen", __func__);
                return (-1);
diff --git usr.sbin/rad/control.h usr.sbin/rad/control.h
index 8ce9b1f22d7..2df40f49351 100644
--- usr.sbin/rad/control.h
+++ usr.sbin/rad/control.h
@@ -16,17 +16,14 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-struct {
+struct control_state {
        struct event    ev;
        struct event    evt;
        int             fd;
-} control_state;
-
-struct ctl_conn {
-       TAILQ_ENTRY(ctl_conn)   entry;
-       struct imsgev           iev;
 };
 
+extern struct control_state    control_state;
+
 int    control_init(char *);
 int    control_listen(void);
 void   control_accept(int, short, void *);
diff --git usr.sbin/rad/frontend.c usr.sbin/rad/frontend.c
index 6655ab5d197..5d47b5ecdaf 100644
--- usr.sbin/rad/frontend.c
+++ usr.sbin/rad/frontend.c
@@ -150,9 +150,10 @@ void                        route_receive(int, short, void 
*);
 void                    handle_route_message(struct rt_msghdr *,
                             struct sockaddr **);
 
-struct rad_conf        *frontend_conf;
 struct imsgev          *iev_main;
 struct imsgev          *iev_engine;
+struct control_state    control_state;
+struct rad_conf                *frontend_conf;
 struct event            ev_route;
 int                     ioctlsock = -1, routesock = -1;
 struct ipv6_mreq        all_routers;
@@ -477,7 +478,6 @@ frontend_dispatch_main(int fd, short event, void *bula)
                                    __func__);
                        control_state.fd = fd;
                        /* Listen on control socket. */
-                       TAILQ_INIT(&ctl_conns);
                        control_listen();
                        break;
                default:
diff --git usr.sbin/rad/frontend.h usr.sbin/rad/frontend.h
index 067ed7e34a0..d86ef6ebfeb 100644
--- usr.sbin/rad/frontend.h
+++ usr.sbin/rad/frontend.h
@@ -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 *);

commit 4ec7ef9d045b337428b171e6edb64096142d5ed5
Author: Florian Obser <flor...@narrans.de>
Date:   Mon Jan 18 08:44:08 2021 +0100

    Use per process unique names for imsgevs; unbreaks -fno-common.
    Problem reported by mortimer

diff --git usr.sbin/rad/engine.c usr.sbin/rad/engine.c
index 6c1cb0ccb15..e6396ad0d1f 100644
--- usr.sbin/rad/engine.c
+++ usr.sbin/rad/engine.c
@@ -65,8 +65,8 @@ struct engine_iface   *find_engine_iface_by_id(uint32_t);
 void                    iface_timeout(int, short, void *);
 
 struct rad_conf        *engine_conf;
-struct imsgev          *iev_frontend;
-struct imsgev          *iev_main;
+struct imsgev          *iev_engine_to_frontend;
+struct imsgev          *iev_engine_to_main;
 struct sockaddr_in6     all_nodes;
 
 void
@@ -127,17 +127,18 @@ engine(int debug, int verbose)
        signal(SIGHUP, SIG_IGN);
 
        /* Setup pipe and event handler to the main process. */
-       if ((iev_main = malloc(sizeof(struct imsgev))) == NULL)
+       if ((iev_engine_to_main = malloc(sizeof(struct imsgev))) == NULL)
                fatal(NULL);
 
-       imsg_init(&iev_main->ibuf, 3);
-       iev_main->handler = engine_dispatch_main;
+       imsg_init(&iev_engine_to_main->ibuf, 3);
+       iev_engine_to_main->handler = engine_dispatch_main;
 
        /* Setup event handlers. */
-       iev_main->events = EV_READ;
-       event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events,
-           iev_main->handler, iev_main);
-       event_add(&iev_main->ev, NULL);
+       iev_engine_to_main->events = EV_READ;
+       event_set(&iev_engine_to_main->ev, iev_engine_to_main->ibuf.fd,
+           iev_engine_to_main->events, iev_engine_to_main->handler,
+           iev_engine_to_main);
+       event_add(&iev_engine_to_main->ev, NULL);
 
        all_nodes.sin6_len = sizeof(all_nodes);
        all_nodes.sin6_family = AF_INET6;
@@ -155,15 +156,15 @@ __dead void
 engine_shutdown(void)
 {
        /* Close pipes. */
-       msgbuf_clear(&iev_frontend->ibuf.w);
-       close(iev_frontend->ibuf.fd);
-       msgbuf_clear(&iev_main->ibuf.w);
-       close(iev_main->ibuf.fd);
+       msgbuf_clear(&iev_engine_to_frontend->ibuf.w);
+       close(iev_engine_to_frontend->ibuf.fd);
+       msgbuf_clear(&iev_engine_to_main->ibuf.w);
+       close(iev_engine_to_main->ibuf.fd);
 
        config_clear(engine_conf);
 
-       free(iev_frontend);
-       free(iev_main);
+       free(iev_engine_to_frontend);
+       free(iev_engine_to_main);
 
        log_info("engine exiting");
        exit(0);
@@ -172,7 +173,7 @@ engine_shutdown(void)
 int
 engine_imsg_compose_frontend(int type, pid_t pid, void *data, uint16_t datalen)
 {
-       return (imsg_compose_event(iev_frontend, type, 0, pid, -1,
+       return (imsg_compose_event(iev_engine_to_frontend, type, 0, pid, -1,
            data, datalen));
 }
 
@@ -295,7 +296,7 @@ engine_dispatch_main(int fd, short event, void *bula)
                         * Setup pipe and event handler to the frontend
                         * process.
                         */
-                       if (iev_frontend)
+                       if (iev_engine_to_frontend)
                                fatalx("%s: received unexpected imsg fd "
                                    "to engine", __func__);
 
@@ -303,18 +304,21 @@ engine_dispatch_main(int fd, short event, void *bula)
                                fatalx("%s: expected to receive imsg fd to "
                                   "engine but didn't receive any", __func__);
 
-                       iev_frontend = malloc(sizeof(struct imsgev));
-                       if (iev_frontend == NULL)
+                       iev_engine_to_frontend = malloc(sizeof(struct imsgev));
+                       if (iev_engine_to_frontend == NULL)
                                fatal(NULL);
 
-                       imsg_init(&iev_frontend->ibuf, fd);
-                       iev_frontend->handler = engine_dispatch_frontend;
-                       iev_frontend->events = EV_READ;
-
-                       event_set(&iev_frontend->ev, iev_frontend->ibuf.fd,
-                       iev_frontend->events, iev_frontend->handler,
-                           iev_frontend);
-                       event_add(&iev_frontend->ev, NULL);
+                       imsg_init(&iev_engine_to_frontend->ibuf, fd);
+                       iev_engine_to_frontend->handler =
+                           engine_dispatch_frontend;
+                       iev_engine_to_frontend->events = EV_READ;
+
+                       event_set(&iev_engine_to_frontend->ev,
+                           iev_engine_to_frontend->ibuf.fd,
+                           iev_engine_to_frontend->events,
+                           iev_engine_to_frontend->handler,
+                           iev_engine_to_frontend);
+                       event_add(&iev_engine_to_frontend->ev, NULL);
                        break;
                case IMSG_RECONF_CONF:
                        if (nconf != NULL)
diff --git usr.sbin/rad/frontend.c usr.sbin/rad/frontend.c
index 5d47b5ecdaf..f4baf5e2313 100644
--- usr.sbin/rad/frontend.c
+++ usr.sbin/rad/frontend.c
@@ -150,10 +150,10 @@ void                       route_receive(int, short, void 
*);
 void                    handle_route_message(struct rt_msghdr *,
                             struct sockaddr **);
 
-struct imsgev          *iev_main;
-struct imsgev          *iev_engine;
 struct control_state    control_state;
 struct rad_conf                *frontend_conf;
+struct imsgev          *iev_frontend_to_main;
+struct imsgev          *iev_frontend_to_engine;
 struct event            ev_route;
 int                     ioctlsock = -1, routesock = -1;
 struct ipv6_mreq        all_routers;
@@ -225,14 +225,15 @@ frontend(int debug, int verbose)
        signal(SIGHUP, SIG_IGN);
 
        /* Setup pipe and event handler to the parent process. */
-       if ((iev_main = malloc(sizeof(struct imsgev))) == NULL)
+       if ((iev_frontend_to_main = malloc(sizeof(struct imsgev))) == NULL)
                fatal(NULL);
-       imsg_init(&iev_main->ibuf, 3);
-       iev_main->handler = frontend_dispatch_main;
-       iev_main->events = EV_READ;
-       event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events,
-           iev_main->handler, iev_main);
-       event_add(&iev_main->ev, NULL);
+       imsg_init(&iev_frontend_to_main->ibuf, 3);
+       iev_frontend_to_main->handler = frontend_dispatch_main;
+       iev_frontend_to_main->events = EV_READ;
+       event_set(&iev_frontend_to_main->ev, iev_frontend_to_main->ibuf.fd,
+           iev_frontend_to_main->events, iev_frontend_to_main->handler,
+           iev_frontend_to_main);
+       event_add(&iev_frontend_to_main->ev, NULL);
 
        if (inet_pton(AF_INET6, "ff02::2",
            &all_routers.ipv6mr_multiaddr.s6_addr) == -1)
@@ -260,17 +261,17 @@ __dead void
 frontend_shutdown(void)
 {
        /* Close pipes. */
-       msgbuf_write(&iev_engine->ibuf.w);
-       msgbuf_clear(&iev_engine->ibuf.w);
-       close(iev_engine->ibuf.fd);
-       msgbuf_write(&iev_main->ibuf.w);
-       msgbuf_clear(&iev_main->ibuf.w);
-       close(iev_main->ibuf.fd);
+       msgbuf_write(&iev_frontend_to_engine->ibuf.w);
+       msgbuf_clear(&iev_frontend_to_engine->ibuf.w);
+       close(iev_frontend_to_engine->ibuf.fd);
+       msgbuf_write(&iev_frontend_to_main->ibuf.w);
+       msgbuf_clear(&iev_frontend_to_main->ibuf.w);
+       close(iev_frontend_to_main->ibuf.fd);
 
        config_clear(frontend_conf);
 
-       free(iev_engine);
-       free(iev_main);
+       free(iev_frontend_to_engine);
+       free(iev_frontend_to_main);
 
        log_info("frontend exiting");
        exit(0);
@@ -279,15 +280,15 @@ frontend_shutdown(void)
 int
 frontend_imsg_compose_main(int type, pid_t pid, void *data, uint16_t datalen)
 {
-       return (imsg_compose_event(iev_main, type, 0, pid, -1, data,
-           datalen));
+       return (imsg_compose_event(iev_frontend_to_main, type, 0, pid, -1,
+           data, datalen));
 }
 
 int
 frontend_imsg_compose_engine(int type, pid_t pid, void *data, uint16_t datalen)
 {
-       return (imsg_compose_event(iev_engine, type, 0, pid, -1, data,
-           datalen));
+       return (imsg_compose_event(iev_frontend_to_engine, type, 0, pid, -1,
+           data, datalen));
 }
 
 void
@@ -329,7 +330,7 @@ frontend_dispatch_main(int fd, short event, void *bula)
                         * Setup pipe and event handler to the engine
                         * process.
                         */
-                       if (iev_engine)
+                       if (iev_frontend_to_engine)
                                fatalx("%s: received unexpected imsg fd to "
                                    "frontend", __func__);
                        if ((fd = imsg.fd) == -1)
@@ -337,17 +338,21 @@ frontend_dispatch_main(int fd, short event, void *bula)
                                   "frontend but didn't receive any",
                                   __func__);
 
-                       iev_engine = malloc(sizeof(struct imsgev));
-                       if (iev_engine == NULL)
+                       iev_frontend_to_engine = malloc(sizeof(struct imsgev));
+                       if (iev_frontend_to_engine == NULL)
                                fatal(NULL);
 
-                       imsg_init(&iev_engine->ibuf, fd);
-                       iev_engine->handler = frontend_dispatch_engine;
-                       iev_engine->events = EV_READ;
-
-                       event_set(&iev_engine->ev, iev_engine->ibuf.fd,
-                       iev_engine->events, iev_engine->handler, iev_engine);
-                       event_add(&iev_engine->ev, NULL);
+                       imsg_init(&iev_frontend_to_engine->ibuf, fd);
+                       iev_frontend_to_engine->handler =
+                           frontend_dispatch_engine;
+                       iev_frontend_to_engine->events = EV_READ;
+
+                       event_set(&iev_frontend_to_engine->ev,
+                           iev_frontend_to_engine->ibuf.fd,
+                           iev_frontend_to_engine->events,
+                           iev_frontend_to_engine->handler,
+                           iev_frontend_to_engine);
+                       event_add(&iev_frontend_to_engine->ev, NULL);
                        break;
                case IMSG_RECONF_CONF:
                        if (nconf != NULL)
diff --git usr.sbin/rad/rad.c usr.sbin/rad/rad.c
index 602c20b3706..4d178582709 100644
--- usr.sbin/rad/rad.c
+++ usr.sbin/rad/rad.c
@@ -78,8 +78,8 @@ int   main_sendboth(enum imsg_type, void *, uint16_t);
 void   in6_prefixlen2mask(struct in6_addr *, int len);
 
 struct rad_conf        *main_conf;
-struct imsgev          *iev_frontend;
-struct imsgev          *iev_engine;
+struct imsgev          *iev_main_to_frontend;
+struct imsgev          *iev_main_to_engine;
 char                   *conffile;
 
 pid_t   frontend_pid;
@@ -242,26 +242,29 @@ main(int argc, char *argv[])
 
        /* Setup pipes to children. */
 
-       if ((iev_frontend = malloc(sizeof(struct imsgev))) == NULL ||
-           (iev_engine = malloc(sizeof(struct imsgev))) == NULL)
+       if ((iev_main_to_frontend = malloc(sizeof(struct imsgev))) == NULL ||
+           (iev_main_to_engine = malloc(sizeof(struct imsgev))) == NULL)
                fatal(NULL);
-       imsg_init(&iev_frontend->ibuf, pipe_main2frontend[0]);
-       iev_frontend->handler = main_dispatch_frontend;
-       imsg_init(&iev_engine->ibuf, pipe_main2engine[0]);
-       iev_engine->handler = main_dispatch_engine;
+       imsg_init(&iev_main_to_frontend->ibuf, pipe_main2frontend[0]);
+       iev_main_to_frontend->handler = main_dispatch_frontend;
+       imsg_init(&iev_main_to_engine->ibuf, pipe_main2engine[0]);
+       iev_main_to_engine->handler = main_dispatch_engine;
 
        /* Setup event handlers for pipes to engine & frontend. */
-       iev_frontend->events = EV_READ;
-       event_set(&iev_frontend->ev, iev_frontend->ibuf.fd,
-           iev_frontend->events, iev_frontend->handler, iev_frontend);
-       event_add(&iev_frontend->ev, NULL);
-
-       iev_engine->events = EV_READ;
-       event_set(&iev_engine->ev, iev_engine->ibuf.fd, iev_engine->events,
-           iev_engine->handler, iev_engine);
-       event_add(&iev_engine->ev, NULL);
-
-       if (main_imsg_send_ipc_sockets(&iev_frontend->ibuf, &iev_engine->ibuf))
+       iev_main_to_frontend->events = EV_READ;
+       event_set(&iev_main_to_frontend->ev, iev_main_to_frontend->ibuf.fd,
+           iev_main_to_frontend->events, iev_main_to_frontend->handler,
+           iev_main_to_frontend);
+       event_add(&iev_main_to_frontend->ev, NULL);
+
+       iev_main_to_engine->events = EV_READ;
+       event_set(&iev_main_to_engine->ev, iev_main_to_engine->ibuf.fd,
+           iev_main_to_engine->events, iev_main_to_engine->handler,
+           iev_main_to_engine);
+       event_add(&iev_main_to_engine->ev, NULL);
+
+       if (main_imsg_send_ipc_sockets(&iev_main_to_frontend->ibuf,
+           &iev_main_to_engine->ibuf))
                fatal("could not establish imsg links");
 
        if ((frontend_routesock = socket(AF_ROUTE, SOCK_RAW | SOCK_CLOEXEC,
@@ -303,10 +306,10 @@ main_shutdown(void)
        int      status;
 
        /* Close pipes. */
-       msgbuf_clear(&iev_frontend->ibuf.w);
-       close(iev_frontend->ibuf.fd);
-       msgbuf_clear(&iev_engine->ibuf.w);
-       close(iev_engine->ibuf.fd);
+       msgbuf_clear(&iev_main_to_frontend->ibuf.w);
+       close(iev_main_to_frontend->ibuf.fd);
+       msgbuf_clear(&iev_main_to_engine->ibuf.w);
+       close(iev_main_to_engine->ibuf.fd);
 
        config_clear(main_conf);
 
@@ -322,8 +325,8 @@ main_shutdown(void)
                            "frontend", WTERMSIG(status));
        } while (pid != -1 || (pid == -1 && errno == EINTR));
 
-       free(iev_frontend);
-       free(iev_engine);
+       free(iev_main_to_frontend);
+       free(iev_main_to_engine);
 
        log_info("terminating");
        exit(0);
@@ -492,9 +495,9 @@ main_dispatch_engine(int fd, short event, void *bula)
 int
 main_imsg_compose_frontend(int type, int fd, void *data, uint16_t datalen)
 {
-       if (iev_frontend)
-               return (imsg_compose_event(iev_frontend, type, 0, 0, fd, data,
-                   datalen));
+       if (iev_main_to_frontend)
+               return (imsg_compose_event(iev_main_to_frontend, type, 0, 0, fd,
+                   data, datalen));
        else
                return (-1);
 }
@@ -502,8 +505,8 @@ main_imsg_compose_frontend(int type, int fd, void *data, 
uint16_t datalen)
 void
 main_imsg_compose_engine(int type, pid_t pid, void *data, uint16_t datalen)
 {
-       if (iev_engine)
-               imsg_compose_event(iev_engine, type, 0, pid, -1, data,
+       if (iev_main_to_engine)
+               imsg_compose_event(iev_main_to_engine, type, 0, pid, -1, data,
                    datalen);
 }
 
@@ -635,9 +638,11 @@ main_imsg_send_config(struct rad_conf *xconf)
 int
 main_sendboth(enum imsg_type type, void *buf, uint16_t len)
 {
-       if (imsg_compose_event(iev_frontend, type, 0, 0, -1, buf, len) == -1)
+       if (imsg_compose_event(iev_main_to_frontend, type, 0, 0, -1, buf, len)
+           == -1)
                return (-1);
-       if (imsg_compose_event(iev_engine, type, 0, 0, -1, buf, len) == -1)
+       if (imsg_compose_event(iev_main_to_engine, type, 0, 0, -1, buf, len)
+           == -1)
                return (-1);
        return (0);
 }


-- 
I'm not entirely sure you are real.

Reply via email to