From 0abb27e6e3a5eff43b4dfcc0455aa414a0837ed5 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Sat, 2 Mar 2013 00:55:15 +0000 Subject: Ensure that the jaildaemon dies when its fork slave is gone --- jaildaemon.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/jaildaemon.c b/jaildaemon.c index 797f547..ae750f3 100644 --- a/jaildaemon.c +++ b/jaildaemon.c @@ -456,6 +456,12 @@ int main( int argc, char **argv ) { EV_SET( &ke, g_uds, EVFILT_VNODE, EV_ADD, NOTE_DELETE | NOTE_LINK, 0, 0); kevent( kq, &ke, 1, NULL, 0, NULL ); + /* We want to be notified if the fork slave died. This is a good time to + die, too*/ + EV_SET( &ke, g_fork_slave_fd, EVFILT_READ, EV_ADD, 0, 0, 0); + kevent( kq, &ke, 1, NULL, 0, NULL ); + + /* If daemon was started with some initial script, fire it now -- this leaks some information in the command line to all jails and thus is disabled @@ -554,6 +560,15 @@ int main( int argc, char **argv ) { /* Takes a copy of our task and all string members */ add_task_to_kqueue( kq, &task ); + } else if( (int)ke.ident == g_fork_slave_fd ) { + /* If we see activity on the socket to the fork slave in + this place, that can only mean that the slave died (EOF), + or that something strange is going on over there. For now + we only warn, we may switch to exerr() in the future. */ + if( ke.flags == EV_EOF ) + exerr( "Fork slave died. We die, too." ); + else + warn( "Spurious packet from fork slave." ); } break; case EVFILT_VNODE: -- cgit v1.2.3