diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2015-10-16 20:12:07 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2015-10-16 20:12:07 +0000 |
commit | 606b7ab99f4f7cf1821126ebd85d8bd77c25dd4b (patch) | |
tree | ab29f885725e0f8058d6e486df76792d143f1f2c /usr.sbin | |
parent | b2adbd7c5e9f15045bce07674d3825c9293c4bb3 (diff) |
naddy would like the child to exit when the parent dies.
hook up a pipe between them and watch for eof in the child.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/rebound/rebound.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/usr.sbin/rebound/rebound.c b/usr.sbin/rebound/rebound.c index dcad25a35c1..2c30a28530d 100644 --- a/usr.sbin/rebound/rebound.c +++ b/usr.sbin/rebound/rebound.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rebound.c,v 1.23 2015/10/16 18:47:52 tedu Exp $ */ +/* $OpenBSD: rebound.c,v 1.24 2015/10/16 20:12:06 tedu Exp $ */ /* * Copyright (c) 2015 Ted Unangst <tedu@openbsd.org> * @@ -356,7 +356,7 @@ readconfig(FILE *conf, struct sockaddr_storage *remoteaddr) } static int -launch(const char *confname, int ud, int ld, int kq) +launch(const char *confname, int ud, int ld, int kq, int *pfd) { struct sockaddr_storage remoteaddr; struct kevent chlist[2], kev[4]; @@ -377,6 +377,7 @@ launch(const char *confname, int ud, int ld, int kq) if (!debug) { if ((child = fork())) return child; + close(pfd[1]); } if (!(pwd = getpwnam("_rebound"))) @@ -406,7 +407,8 @@ launch(const char *confname, int ud, int ld, int kq) EV_SET(&kev[0], ud, EVFILT_READ, EV_ADD, 0, 0, NULL); EV_SET(&kev[1], ld, EVFILT_READ, EV_ADD, 0, 0, NULL); EV_SET(&kev[2], SIGHUP, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL); - kevent(kq, kev, 3, NULL, 0, NULL); + EV_SET(&kev[3], pfd[0], EVFILT_READ, EV_ADD, 0, 0, NULL); + kevent(kq, kev, 4, NULL, 0, NULL); signal(SIGHUP, SIG_IGN); logmsg(LOG_INFO, "worker process going to work"); while (1) { @@ -420,6 +422,11 @@ launch(const char *confname, int ud, int ld, int kq) if (kev[i].filter == EVFILT_SIGNAL) { logmsg(LOG_INFO, "hupped, exiting"); exit(0); + } else if (kev[i].ident == pfd[0]) { + if (kev[i].flags & EV_EOF) { + logmsg(LOG_INFO, "parent died"); + exit(0); + } } else if (kev[i].ident == ud) { req = newrequest(ud, (struct sockaddr *)&remoteaddr); @@ -515,6 +522,7 @@ main(int argc, char **argv) struct sockaddr_in bindaddr; int r, kq, ld, ud, ch; int one; + int pfd[2]; int childdead, hupped; pid_t child; struct kevent kev; @@ -570,8 +578,10 @@ main(int argc, char **argv) if (listen(ld, 10) == -1) err(1, "listen"); + pipe(pfd); + if (debug) { - launch(conffile, ud, ld, -1); + launch(conffile, ud, ld, -1, pfd); return 1; } @@ -583,7 +593,7 @@ main(int argc, char **argv) while (1) { hupped = 0; childdead = 0; - child = launch(conffile, ud, ld, kq); + child = launch(conffile, ud, ld, kq, pfd); if (child == -1) logerr("failed to launch"); |