-/* $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>
*
}
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];
if (!debug) {
if ((child = fork()))
return child;
+ close(pfd[1]);
}
if (!(pwd = getpwnam("_rebound")))
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) {
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);
struct sockaddr_in bindaddr;
int r, kq, ld, ud, ch;
int one;
+ int pfd[2];
int childdead, hupped;
pid_t child;
struct kevent kev;
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;
}
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");