From ee103ef4b2856d7bb723f79b71044efbbb451847 Mon Sep 17 00:00:00 2001 From: renato Date: Sat, 3 Sep 2016 10:25:36 +0000 Subject: 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@ --- usr.sbin/ospf6d/ospfe.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'usr.sbin/ospf6d/ospfe.c') 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 @@ -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); -- cgit v1.2.3-59-g8ed1b