diff options
author | renato <renato@openbsd.org> | 2016-09-03 10:25:36 +0000 |
---|---|---|
committer | renato <renato@openbsd.org> | 2016-09-03 10:25:36 +0000 |
commit | ee103ef4b2856d7bb723f79b71044efbbb451847 (patch) | |
tree | 4ead8602a3c33d77cd366db66920c8efe6685e16 /usr.sbin/ospf6d/ospfe.c | |
parent | Simplify shutdown process. (diff) | |
download | wireguard-openbsd-ee103ef4b2856d7bb723f79b71044efbbb451847.tar.xz wireguard-openbsd-ee103ef4b2856d7bb723f79b71044efbbb451847.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/ospf6d/ospfe.c')
-rw-r--r-- | usr.sbin/ospf6d/ospfe.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/usr.sbin/ospf6d/ospfe.c b/usr.sbin/ospf6d/ospfe.c index 76edde60abb..2bed57df8e0 100644 --- a/usr.sbin/ospf6d/ospfe.c +++ b/usr.sbin/ospf6d/ospfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.c,v 1.48 2016/09/02 14:06:35 benno Exp $ */ +/* $OpenBSD: ospfe.c,v 1.49 2016/09/03 10:25:36 renato Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -43,7 +43,7 @@ #include "log.h" void ospfe_sig_handler(int, short, void *); -void ospfe_shutdown(void); +__dead void ospfe_shutdown(void); void orig_rtr_lsa_all(struct area *); void orig_rtr_lsa_area(struct area *); struct iface *find_vlink(struct abr_rtr *); @@ -195,12 +195,20 @@ ospfe(struct ospfd_conf *xconf, int pipe_parent2ospfe[2], int pipe_ospfe2rde[2], return (0); } -void +__dead void ospfe_shutdown(void) { struct area *area; 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); + /* stop all interfaces and remove all areas */ while ((area = LIST_FIRST(&oeconf->area_list)) != NULL) { LIST_FOREACH(iface, &area->iface_list, entry) { @@ -216,11 +224,7 @@ ospfe_shutdown(void) close(oeconf->ospf_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); |