diff options
author | Vineeth Sagar <39757522+vsag96@users.noreply.github.com> | 2018-12-07 03:08:34 +0530 |
---|---|---|
committer | Christian Duerr <chrisduerr@users.noreply.github.com> | 2018-12-06 21:38:34 +0000 |
commit | cadbb86eb78854d4aff2e7b38089d75067e41b96 (patch) | |
tree | b5ef6bb926c1dd1bd638202b754090b9104a6501 /src/input.rs | |
parent | f57bd6e12f7e94b767b34a208c66dc88c93f704e (diff) | |
download | r-alacritty-cadbb86eb78854d4aff2e7b38089d75067e41b96.tar.gz r-alacritty-cadbb86eb78854d4aff2e7b38089d75067e41b96.tar.bz2 r-alacritty-cadbb86eb78854d4aff2e7b38089d75067e41b96.zip |
Detach Child process to avoid zombie processes
This makes use of the common double-fork behavior to prevent
spawning zombie processes every time a URL is clicked.
Diffstat (limited to 'src/input.rs')
-rw-r--r-- | src/input.rs | 29 |
1 files changed, 5 insertions, 24 deletions
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), } |