mirror of
https://github.com/watchexec/watchexec.git
synced 2024-11-13 07:41:11 +01:00
Replace before_exec with fork/exec, removing Rust nightly requirement
This commit is contained in:
parent
bdce629782
commit
3bf3086a29
2 changed files with 20 additions and 6 deletions
|
@ -1,5 +1,3 @@
|
|||
#![feature(process_exec)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
extern crate globset;
|
||||
|
|
|
@ -16,7 +16,7 @@ mod imp {
|
|||
pub fn new(cmd: &str, updated_paths: Vec<PathBuf>) -> Result<Process> {
|
||||
use std::io;
|
||||
use std::os::unix::process::CommandExt;
|
||||
use nix::unistd::setpgid;
|
||||
use nix::unistd::*;
|
||||
|
||||
let mut command = Command::new("sh");
|
||||
command.arg("-c").arg(cmd);
|
||||
|
@ -29,9 +29,25 @@ mod imp {
|
|||
command.env("WATCHEXEC_COMMON_PATH", common_path);
|
||||
}
|
||||
|
||||
command.before_exec(|| setpgid(0, 0).map_err(io::Error::from))
|
||||
.spawn()
|
||||
.and_then(|p| Ok(Process { pid: p.id() as i32 }))
|
||||
// Until process_exec lands in stable, handle fork/exec ourselves
|
||||
//command.before_exec(|| setpgid(0, 0).map_err(io::Error::from))
|
||||
//.spawn()
|
||||
//.and_then(|p| Ok(Process { pid: p.id() as i32 }))
|
||||
|
||||
match fork() {
|
||||
Ok(ForkResult::Parent {child, .. }) => {
|
||||
Ok(Process {
|
||||
pid: child as i32
|
||||
})
|
||||
},
|
||||
Ok(ForkResult::Child) => {
|
||||
let _ = setpgid(0, 0);
|
||||
let e = command.exec();
|
||||
|
||||
Err(e)
|
||||
}
|
||||
Err(e) => { Err(io::Error::from(e)) }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn kill(&self) {
|
||||
|
|
Loading…
Reference in a new issue