No need to use before_exec() to call setpgid()

This commit is contained in:
Matt Green 2016-10-20 12:09:51 -04:00
parent b16cbec3ee
commit 03775b61ce
5 changed files with 20 additions and 10 deletions

View File

@ -8,10 +8,10 @@ env:
matrix:
include:
- os: linux
rust: nightly
rust: stable
env: TARGET=x86_64-unknown-linux-gnu
- os: osx
rust: nightly
rust: stable
env: TARGET=x86_64-apple-darwin
script:

View File

@ -22,6 +22,8 @@ Example use cases:
* By default, uses `.gitignore` to determine which files to ignore notifications for
* Support for watching files with a specific extension
* Support for filtering/ignoring events based on glob patterns
* Launches child processes in a new process group
* Sets `$WATCHEXEC_UPDATED_PATH` in the environment of the child process to the first file that triggered a change
* Optionally clears screen between executions
* Optionally restarts the command with every modification (good for servers)
* Does not require a language runtime

View File

@ -3,7 +3,7 @@ environment:
PROJECT_NAME: watchexec
matrix:
- TARGET: x86_64-pc-windows-gnu
CHANNEL: nightly
CHANNEL: stable
# Install Rust and Cargo
# (Based on from https://github.com/rust-lang/libc/blob/master/appveyor.yml)

View File

@ -1,5 +1,3 @@
#![feature(process_exec)]
#[macro_use]
extern crate clap;
extern crate env_logger;

View File

@ -1,4 +1,3 @@
use libc;
use std::process::{Child, Command};
pub struct Runner {
@ -33,6 +32,8 @@ impl Runner {
#[cfg(target_family = "unix")]
fn kill(child: &mut Child) {
use libc;
extern {
fn killpg(pgrp: libc::pid_t, sig: libc::c_int) -> libc::c_int;
}
@ -56,7 +57,7 @@ impl Runner {
#[cfg(target_family = "unix")]
fn invoke(&self, cmd: &str, updated_paths: Vec<&str>) -> Option<Child> {
use std::os::unix::process::CommandExt;
use libc;
let mut command = Command::new("sh");
command.arg("-c").arg(cmd);
@ -65,10 +66,17 @@ impl Runner {
command.env("WATCHEXEC_UPDATED_PATH", updated_paths[0]);
}
command
.before_exec(|| unsafe { libc::setpgid(0, 0); Ok(()) })
let child = command
.spawn()
.ok()
.ok();
if let &Some(ref c) = &child {
unsafe {
libc::setpgid(c.id() as i32, c.id() as i32);
}
}
child
}
pub fn run_command(&mut self, cmd: &str, updated_paths: Vec<&str>) {
@ -98,6 +106,8 @@ impl Runner {
#[cfg(target_family = "unix")]
fn wait(child: &mut Child) {
use libc;
unsafe {
let pid = child.id() as i32;
let status: Box<i32> = Box::new(0);