mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-29 22:51:33 +02:00
[run] Dry spawning the child process
This commit is contained in:
parent
5e44cafb94
commit
ede5505a6b
39
src/run.rs
39
src/run.rs
@ -147,6 +147,19 @@ pub struct ExecHandler {
|
|||||||
child_process: Arc<RwLock<Option<Process>>>,
|
child_process: Arc<RwLock<Option<Process>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ExecHandler {
|
||||||
|
fn spawn(&mut self, ops: Vec<PathOp>) -> Result<()> {
|
||||||
|
let mut guard = self.child_process.write()?;
|
||||||
|
*guard = Some(process::spawn(
|
||||||
|
&self.args.cmd,
|
||||||
|
ops,
|
||||||
|
self.args.no_shell,
|
||||||
|
));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Handler for ExecHandler {
|
impl Handler for ExecHandler {
|
||||||
fn new(args: Args) -> Result<Self> {
|
fn new(args: Args) -> Result<Self> {
|
||||||
let child_process: Arc<RwLock<Option<Process>>> = Arc::new(RwLock::new(None));
|
let child_process: Arc<RwLock<Option<Process>>> = Arc::new(RwLock::new(None));
|
||||||
@ -174,17 +187,12 @@ impl Handler for ExecHandler {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only returns Err() on lock poisoning.
|
||||||
fn on_manual(&mut self) -> Result<bool> {
|
fn on_manual(&mut self) -> Result<bool> {
|
||||||
let mut guard = self.child_process.write()?;
|
self.spawn(Vec::new()).and(Ok(true))
|
||||||
*guard = Some(process::spawn(
|
|
||||||
&self.args.cmd,
|
|
||||||
Vec::new(),
|
|
||||||
self.args.no_shell,
|
|
||||||
));
|
|
||||||
|
|
||||||
Ok(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only returns Err() on lock poisoning.
|
||||||
fn on_update(&mut self, ops: Vec<PathOp>) -> Result<bool> {
|
fn on_update(&mut self, ops: Vec<PathOp>) -> Result<bool> {
|
||||||
// We have three scenarios here:
|
// We have three scenarios here:
|
||||||
//
|
//
|
||||||
@ -207,10 +215,7 @@ impl Handler for ExecHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
debug!("Launching child process");
|
debug!("Launching child process");
|
||||||
{
|
self.spawn(ops)?;
|
||||||
let mut guard = self.child_process.write()?;
|
|
||||||
*guard = Some(process::spawn(&self.args.cmd, ops, self.args.no_shell));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default restart behaviour (--restart was given, but --signal wasn't specified):
|
// Default restart behaviour (--restart was given, but --signal wasn't specified):
|
||||||
@ -225,10 +230,7 @@ impl Handler for ExecHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
debug!("Launching child process");
|
debug!("Launching child process");
|
||||||
{
|
self.spawn(ops)?;
|
||||||
let mut guard = self.child_process.write()?;
|
|
||||||
*guard = Some(process::spawn(&self.args.cmd, ops, self.args.no_shell));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SIGHUP scenario: --signal was given, but --restart was not
|
// SIGHUP scenario: --signal was given, but --restart was not
|
||||||
@ -246,10 +248,7 @@ impl Handler for ExecHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
debug!("Launching child process");
|
debug!("Launching child process");
|
||||||
{
|
self.spawn(ops)?;
|
||||||
let mut guard = self.child_process.write()?;
|
|
||||||
*guard = Some(process::spawn(&self.args.cmd, ops, self.args.no_shell));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user