1mod consts;
2mod control;
3mod watch;
4
5use consts::*;
6pub use control::Control;
7use std::env;
8use watch::Watch;
9pub use watch::WatchConfig;
10
11#[cfg(windows)]
13pub fn ctrl(_cfg: WatchConfig) -> Result<bool, ()> {
14 return Err(());
15}
16
17#[cfg(not(windows))]
19pub fn ctrl(cfg: WatchConfig) -> Result<bool, ()> {
20 let mut args = env::args();
21 let program = args.next().unwrap();
22 let args: Vec<String> = args.collect();
23 if let Ok(ref val) = env::var(CHILD_ENV_KEY) {
24 if val == CHILD_ENV_VAL {
25 return Ok(false);
26 }
27 }
28 use fork::{daemon, Fork};
29 if let Ok(Fork::Child) = daemon(true, true) {
30 let mut watch = Watch::new(program, args, cfg);
31 watch.watch();
32 }
33 return Ok(true);
34}