From 03775b61cedeb19f0b92fe9bbe6ccef9b56ffd68 Mon Sep 17 00:00:00 2001 From: Matt Green Date: Thu, 20 Oct 2016 12:09:51 -0400 Subject: [PATCH] No need to use before_exec() to call setpgid() --- .travis.yml | 4 ++-- README.md | 2 ++ appveyor.yml | 2 +- src/main.rs | 2 -- src/runner.rs | 20 +++++++++++++++----- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index a80ffdb..d0ca463 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/README.md b/README.md index cbadbc3..4d85826 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/appveyor.yml b/appveyor.yml index e49eec1..07245b6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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) diff --git a/src/main.rs b/src/main.rs index c918649..1d99474 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,3 @@ -#![feature(process_exec)] - #[macro_use] extern crate clap; extern crate env_logger; diff --git a/src/runner.rs b/src/runner.rs index 6907a77..dd0a3be 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -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 { - 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 = Box::new(0);