diff options
author | Renato Westphal <renato@cvs.openbsd.org> | 2016-09-02 15:38:09 +0000 |
---|---|---|
committer | Renato Westphal <renato@cvs.openbsd.org> | 2016-09-02 15:38:09 +0000 |
commit | dc6f687483a94c8831397116fc342ac65d51e44e (patch) | |
tree | 4fb9c51c698046581ef6bb07456148e20163f317 /usr.sbin/dvmrpd/dvmrpe.c | |
parent | 56cbad96f7a1c51745b9fa33340c705618f5010a (diff) |
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@
Diffstat (limited to 'usr.sbin/dvmrpd/dvmrpe.c')
-rw-r--r-- | usr.sbin/dvmrpd/dvmrpe.c | 20 |
1 files changed, 12 insertions, 8 deletions
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 <claudio@openbsd.org> @@ -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); |