From dc6f687483a94c8831397116fc342ac65d51e44e Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Fri, 2 Sep 2016 15:38:09 +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. "reads good" claudio@ --- usr.sbin/dvmrpd/dvmrpe.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'usr.sbin/dvmrpd/dvmrpe.c') diff --git a/usr.sbin/dvmrpd/dvmrpe.c b/usr.sbin/dvmrpd/dvmrpe.c index 76b8cb16ea3..f907b122fc2 100644 --- a/usr.sbin/dvmrpd/dvmrpe.c +++ b/usr.sbin/dvmrpd/dvmrpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dvmrpe.c,v 1.17 2016/09/02 15:35:34 renato Exp $ */ +/* $OpenBSD: dvmrpe.c,v 1.18 2016/09/02 15:38:08 renato Exp $ */ /* * Copyright (c) 2005 Claudio Jeker @@ -42,8 +42,8 @@ #include "control.h" #include "log.h" -void dvmrpe_sig_handler(int, short, void *); -void dvmrpe_shutdown(void); +void dvmrpe_sig_handler(int, short, void *); +__dead void dvmrpe_shutdown(void); volatile sig_atomic_t dvmrpe_quit = 0; struct dvmrpd_conf *deconf = NULL; @@ -190,11 +190,19 @@ dvmrpe(struct dvmrpd_conf *xconf, int pipe_parent2dvmrpe[2], return (0); } -void +__dead void dvmrpe_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); + /* stop all interfaces and delete them */ LIST_FOREACH(iface, &deconf->iface_list, entry) { if (if_fsm(iface, IF_EVT_DOWN)) { @@ -205,11 +213,7 @@ dvmrpe_shutdown(void) } /* 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(pkt_ptr); -- cgit v1.2.3