From 400a85befce86ed37d55800d910a39ac9a773a25 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 17 Feb 2019 14:02:03 -0800 Subject: [PATCH] fixup process termination detection on windows --- src/guiloop/glutinloop.rs | 34 ++++++++++++++++++++-------------- src/winpty.rs | 7 ++++++- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/guiloop/glutinloop.rs b/src/guiloop/glutinloop.rs index 34c3fd911..51c534388 100644 --- a/src/guiloop/glutinloop.rs +++ b/src/guiloop/glutinloop.rs @@ -246,6 +246,8 @@ impl GuiEventLoop { loop { match self.tick_rx.try_recv() { Ok(_) => { + #[cfg(not(unix))] + self.test_for_child_exit(); self.do_paint(); } Err(TryRecvError::Empty) => return Ok(()), @@ -261,20 +263,7 @@ impl GuiEventLoop { loop { match self.sigchld_rx.try_recv() { Ok(_) => { - let window_ids: Vec = self - .windows - .borrow_mut() - .by_id - .iter_mut() - .filter_map(|(window_id, window)| match window.test_for_child_exit() { - Ok(_) => None, - Err(_) => Some(*window_id), - }) - .collect(); - - for window_id in window_ids { - self.schedule_window_close(window_id)?; - } + self.test_for_child_exit(); } Err(TryRecvError::Empty) => return Ok(()), Err(err) => bail!("paster_rx disconnected {:?}", err), @@ -282,6 +271,23 @@ impl GuiEventLoop { } } + fn test_for_child_exit(&self) { + let window_ids: Vec = self + .windows + .borrow_mut() + .by_id + .iter_mut() + .filter_map(|(window_id, window)| match window.test_for_child_exit() { + Ok(_) => None, + Err(_) => Some(*window_id), + }) + .collect(); + + for window_id in window_ids { + self.schedule_window_close(window_id).ok(); + } + } + /// Runs the winit event loop. This blocks until a wakeup signal /// is delivered to the event loop. The `GuiSender` is our way /// of trigger those wakeups. diff --git a/src/winpty.rs b/src/winpty.rs index deedc14ac..347a5195b 100644 --- a/src/winpty.rs +++ b/src/winpty.rs @@ -13,6 +13,7 @@ use winpty::winapi::shared::minwindef::DWORD; use winpty::winapi::shared::winerror::{HRESULT, S_OK}; use winpty::winapi::um::fileapi::{ReadFile, WriteFile}; use winpty::winapi::um::handleapi::*; +use winpty::winapi::um::minwinbase::STILL_ACTIVE; use winpty::winapi::um::namedpipeapi::CreatePipe; use winpty::winapi::um::processthreadsapi::*; use winpty::winapi::um::winbase::EXTENDED_STARTUPINFO_PRESENT; @@ -291,7 +292,11 @@ impl Child { let mut status: DWORD = 0; let res = unsafe { GetExitCodeProcess(self.proc.handle, &mut status) }; if res != 0 { - Ok(Some(ExitStatus { status })) + if status == STILL_ACTIVE { + Ok(None) + } else { + Ok(Some(ExitStatus { status })) + } } else { Ok(None) }