summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ripd/ripe.c
diff options
context:
space:
mode:
authorrenato <renato@openbsd.org>2016-09-03 10:28:08 +0000
committerrenato <renato@openbsd.org>2016-09-03 10:28:08 +0000
commitf6798567faf125f5cb86fc536eebc675ecca3a7f (patch)
tree2c5e71a32e8ec5f0ed79d8afd566416fc1ca8891 /usr.sbin/ripd/ripe.c
parentSimplify shutdown process. (diff)
downloadwireguard-openbsd-f6798567faf125f5cb86fc536eebc675ecca3a7f.tar.xz
wireguard-openbsd-f6798567faf125f5cb86fc536eebc675ecca3a7f.zip
Simplify shutdown process.
On shutdown, there's no need to use kill(2) to kill the child processes. Just closing the IPC sockets will make the children receive an EOF, break out from the event loop and then exit. Tha advantages of this "pipe teardown" are: * simpler code; * no need to pledge "proc" in the parent process; * removal of a (hard to trigger) PID reuse race condition. ok benno@ claudio@
Diffstat (limited to 'usr.sbin/ripd/ripe.c')
-rw-r--r--usr.sbin/ripd/ripe.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/usr.sbin/ripd/ripe.c b/usr.sbin/ripd/ripe.c
index b70fb8c151c..2a10c003387 100644
--- a/usr.sbin/ripd/ripe.c
+++ b/usr.sbin/ripd/ripe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ripe.c,v 1.21 2016/09/02 14:07:52 benno Exp $ */
+/* $OpenBSD: ripe.c,v 1.22 2016/09/03 10:28:08 renato Exp $ */
/*
* Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@@ -43,7 +43,7 @@
#include "control.h"
void ripe_sig_handler(int, short, void *);
-void ripe_shutdown(void);
+__dead void ripe_shutdown(void);
struct ripd_conf *oeconf = NULL;
struct imsgev *iev_main;
@@ -450,11 +450,19 @@ ripe_dispatch_rde(int fd, short event, void *bula)
}
}
-void
+__dead void
ripe_shutdown(void)
{
struct iface *iface;
+ /* close pipes */
+ msgbuf_write(&iev_rde->ibuf.w);
+ msgbuf_clear(&iev_rde->ibuf.w);
+ close(iev_rde->ibuf.fd);
+ msgbuf_write(&iev_main->ibuf.w);
+ msgbuf_clear(&iev_main->ibuf.w);
+ close(iev_main->ibuf.fd);
+
LIST_FOREACH(iface, &oeconf->iface_list, entry) {
if (if_fsm(iface, IF_EVT_DOWN)) {
log_debug("error stopping interface %s",
@@ -469,11 +477,7 @@ ripe_shutdown(void)
close(oeconf->rip_socket);
/* clean up */
- msgbuf_write(&iev_rde->ibuf.w);
- msgbuf_clear(&iev_rde->ibuf.w);
free(iev_rde);
- msgbuf_write(&iev_main->ibuf.w);
- msgbuf_clear(&iev_main->ibuf.w);
free(iev_main);
free(oeconf);
free(pkt_ptr);