diff --git a/src/gliumwindows.rs b/src/gliumwindows.rs index 38d6d8932..1d7f822e8 100644 --- a/src/gliumwindows.rs +++ b/src/gliumwindows.rs @@ -426,4 +426,19 @@ impl TerminalWindow { pub fn need_paint(&self) -> bool { self.terminal.has_dirty_lines() } + + pub fn test_for_child_exit(&mut self) -> Result<(), Error> { + match self.process.try_wait() { + Ok(Some(status)) => { + bail!("child exited: {}", status); + } + Ok(None) => { + println!("child still running"); + Ok(()) + } + Err(e) => { + bail!("failed to wait for child: {}", e); + } + } + } } diff --git a/src/main.rs b/src/main.rs index d1c8ef661..08ade719a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,6 +93,9 @@ fn run_glium( let poll = Poll::new()?; poll.register(&master, Token(0), Ready::readable(), PollOpt::edge())?; + let waiter = sigchld::ChildWaiter::new()?; + poll.register(&waiter, Token(2), Ready::readable(), PollOpt::edge())?; + let mut events_loop = glium::glutin::EventsLoop::new(); let mut window = gliumwindows::TerminalWindow::new( @@ -120,7 +123,13 @@ fn run_glium( if poll.poll(&mut events, Some(Duration::new(0, 2000)))? != 0 { for event in &events { if event.token() == Token(0) && event.readiness().is_readable() { - window.handle_pty_readable_event(); + window.handle_pty_readable_event()?; + } + if event.token() == Token(2) { + println!("sigchld ready"); + let pid = waiter.read_one()?; + println!("got sigchld from pid {}", pid); + window.test_for_child_exit()?; } } } else if window.need_paint() {