diff --git a/CHANGELOG.md b/CHANGELOG.md index 918f94dc..6a88c579 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed a bad type conversion which could cause underflow on a window resize - Alacritty now spawns a login shell on macOS, as with Terminal.app and iTerm2 +- Fixed zombie processes sticking around after launching URLs ## Version 0.2.3 diff --git a/src/input.rs b/src/input.rs index 051a38db..3eafa437 100644 --- a/src/input.rs +++ b/src/input.rs @@ -20,10 +20,7 @@ //! determine what to do when a non-modifier key is pressed. use std::borrow::Cow; use std::mem; -use std::process::Command; use std::time::Instant; -#[cfg(not(windows))] -use std::os::unix::process::CommandExt; use copypasta::{Clipboard, Load, Buffer as ClipboardBuffer}; use glutin::{ElementState, MouseButton, TouchPhase, MouseScrollDelta, ModifiersState, KeyboardInput}; @@ -35,6 +32,7 @@ use index::{Line, Column, Side, Point}; use term::SizeInfo; use term::mode::TermMode; use util::fmt::Red; +use util::start_daemon; pub const FONT_SIZE_STEP: f32 = 0.5; @@ -239,26 +237,9 @@ impl Action { Action::Command(ref program, ref args) => { trace!("running command: {} {:?}", program, args); - #[cfg(not(windows))] - let spawned = Command::new(program) - .args(args) - .before_exec(|| { - // Detach forked process from Alacritty. This will cause - // init or whatever to clean up child processes for us. - unsafe { ::libc::daemon(1, 0); } - Ok(()) - }) - .spawn(); - - #[cfg(windows)] - let spawned = Command::new(program) - .args(args) - .spawn(); - - match spawned - { - Ok(child) => { - debug!("spawned new proc with pid: {}", child.id()); + match start_daemon(program, args) { + Ok(_) => { + debug!("spawned new proc"); }, Err(err) => { warn!("couldn't run command: {}", err); @@ -557,7 +538,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { let mut args = launcher.args().to_vec(); args.push(text); - match Command::new(launcher.program()).args(&args).spawn() { + match start_daemon(launcher.program(), &args) { Ok(_) => debug!("Launched: {} {:?}", launcher.program(), args), Err(_) => warn!("Unable to launch: {} {:?}", launcher.program(), args), } diff --git a/src/util.rs b/src/util.rs index 6065e01b..3b981aa6 100644 --- a/src/util.rs +++ b/src/util.rs @@ -11,25 +11,20 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -use std::cmp; - -#[cfg(not(feature = "nightly"))] -#[inline(always)] -pub unsafe fn unlikely(x: bool) -> bool { - x -} - -#[cfg(feature = "nightly")] -pub use ::std::intrinsics::unlikely; +#[cfg(not(windows))] +use std::os::unix::process::CommandExt; +use std::process::Command; +use std::{cmp, io}; /// Threading utilities pub mod thread { /// Like `thread::spawn`, but with a `name` argument pub fn spawn_named(name: S, f: F) -> ::std::thread::JoinHandle - where F: FnOnce() -> T, - F: Send + 'static, - T: Send + 'static, - S: Into + where + F: FnOnce() -> T, + F: Send + 'static, + T: Send + 'static, + S: Into, { ::std::thread::Builder::new() .name(name.into()) @@ -37,7 +32,7 @@ pub mod thread { .expect("thread spawn works") } - pub use ::std::thread::*; + pub use std::thread::*; } pub fn limit(value: T, min: T, max: T) -> T { @@ -81,6 +76,24 @@ pub mod fmt { } } +#[cfg(not(windows))] +pub fn start_daemon(program: &str, args: &[String]) -> io::Result<()> { + Command::new(program) + .args(args) + .before_exec(|| unsafe { + ::libc::daemon(1, 0); + Ok(()) + }) + .spawn()? + .wait() + .map(|_| ()) +} + +#[cfg(windows)] +pub fn start_daemon(program: &str, args: &[String]) -> io::Result<()> { + Command::new(program).args(args).spawn().map(|_| ()) +} + #[cfg(test)] mod tests { use super::limit;