summaryrefslogtreecommitdiff
path: root/sbin/iked/proc.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/iked/proc.c')
-rw-r--r--sbin/iked/proc.c59
1 files changed, 56 insertions, 3 deletions
diff --git a/sbin/iked/proc.c b/sbin/iked/proc.c
index 69078840e5d..534427b2b65 100644
--- a/sbin/iked/proc.c
+++ b/sbin/iked/proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.c,v 1.41 2024/02/15 19:04:12 tobhe Exp $ */
+/* $OpenBSD: proc.c,v 1.42 2024/02/15 20:10:45 tobhe Exp $ */
/*
* Copyright (c) 2010 - 2016 Reyk Floeter <reyk@openbsd.org>
@@ -155,14 +155,19 @@ proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc,
}
void
-proc_connect(struct privsep *ps)
+proc_connect(struct privsep *ps, void (*connected)(struct privsep *))
{
struct imsgev *iev;
unsigned int src, dst, inst;
/* Don't distribute any sockets if we are not really going to run. */
- if (ps->ps_noaction)
+ if (ps->ps_noaction) {
+ if (connected == NULL)
+ fatalx("%s: missing callback", __func__);
+ connected(ps);
return;
+ }
+ ps->ps_connected = connected;
for (dst = 0; dst < PROC_MAX; dst++) {
/* We don't communicate with ourselves. */
@@ -187,6 +192,27 @@ proc_connect(struct privsep *ps)
proc_open(ps, src, dst);
}
+
+ /*
+ * Finally, send a ready message to everyone:
+ * When this message is processed by the receiver, it has
+ * already processed all IMSG_CTL_PROCFD messages and all
+ * pipes are ready.
+ */
+ for (dst = 0; dst < PROC_MAX; dst++) {
+ if (dst == PROC_PARENT)
+ continue;
+ for (inst = 0; inst < ps->ps_instances[dst]; inst++) {
+ if (proc_compose_imsg(ps, dst, inst, IMSG_CTL_PROCREADY,
+ -1, -1, NULL, 0) == -1)
+ fatal("%s: proc_compose_imsg", __func__);
+ ps->ps_connecting++;
+#if DEBUG
+ log_debug("%s: #%d %s %d", __func__,
+ ps->ps_connecting, ps->ps_title[dst], inst + 1);
+#endif
+ }
+ }
}
void
@@ -663,6 +689,33 @@ proc_dispatch(int fd, short event, void *arg)
proc_accept(ps, imsg_get_fd(&imsg), pf.pf_procid,
pf.pf_instance);
break;
+ case IMSG_CTL_PROCREADY:
+#if DEBUG
+ log_debug("%s: ready-%s: #%d %s %d -> %s %d", __func__,
+ p->p_id == PROC_PARENT ? "req" : "ack",
+ ps->ps_connecting, p->p_title, imsg.hdr.pid,
+ title, ps->ps_instance + 1);
+#endif
+ if (p->p_id == PROC_PARENT) {
+ /* ack that we are ready */
+ if (proc_compose_imsg(ps, PROC_PARENT, 0,
+ IMSG_CTL_PROCREADY, -1, -1, NULL, 0) == -1)
+ fatal("%s: proc_compose_imsg", __func__);
+ } else {
+ /* parent received ack */
+ if (ps->ps_connecting == 0)
+ fatalx("%s: wrong acks", __func__);
+ if (ps->ps_instance != 0)
+ fatalx("%s: wrong instance %d",
+ __func__, ps->ps_instance);
+ if (ps->ps_connected == NULL)
+ fatalx("%s: missing callback", __func__);
+ if (--ps->ps_connecting == 0) {
+ log_debug("%s: all connected", __func__);
+ ps->ps_connected(ps);
+ }
+ }
+ break;
default:
fatalx("%s: %s %d got invalid imsg %d peerid %d "
"from %s %d",