rustfmt & clippy fixes
This commit is contained in:
parent
2dd2e72214
commit
171132a722
|
@ -83,8 +83,8 @@ pub fn get_args() -> Args {
|
||||||
.long("force-poll")
|
.long("force-poll")
|
||||||
.value_name("interval"))
|
.value_name("interval"))
|
||||||
.arg(Arg::with_name("kill")
|
.arg(Arg::with_name("kill")
|
||||||
.help("Send SIGKILL to child processes")
|
.help("Send SIGKILL to child processes")
|
||||||
.long("kill"))
|
.long("kill"))
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let cmd = values_t!(args.values_of("command"), String).unwrap().join(" ");
|
let cmd = values_t!(args.values_of("command"), String).unwrap().join(" ");
|
||||||
|
|
|
@ -32,7 +32,7 @@ use std::path::Path;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use std::sync::mpsc::{channel, Receiver};
|
use std::sync::mpsc::{channel, Receiver};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::path::{PathBuf};
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use notification_filter::NotificationFilter;
|
use notification_filter::NotificationFilter;
|
||||||
use process::Process;
|
use process::Process;
|
||||||
|
@ -95,7 +95,7 @@ fn main() {
|
||||||
} else {
|
} else {
|
||||||
child.terminate();
|
child.terminate();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Signal::Stop => child.pause(),
|
Signal::Stop => child.pause(),
|
||||||
Signal::Continue => child.resume(),
|
Signal::Continue => child.resume(),
|
||||||
Signal::ChildExit => child.reap(),
|
Signal::ChildExit => child.reap(),
|
||||||
|
|
|
@ -20,6 +20,8 @@ mod imp {
|
||||||
cvar: Condvar,
|
cvar: Condvar,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unknown_lints)]
|
||||||
|
#[allow(mutex_atomic)]
|
||||||
impl Process {
|
impl Process {
|
||||||
pub fn new(cmd: &str, updated_paths: Vec<PathBuf>) -> Result<Process> {
|
pub fn new(cmd: &str, updated_paths: Vec<PathBuf>) -> Result<Process> {
|
||||||
use nix::unistd::*;
|
use nix::unistd::*;
|
||||||
|
@ -98,10 +100,10 @@ mod imp {
|
||||||
let mut finished = true;
|
let mut finished = true;
|
||||||
loop {
|
loop {
|
||||||
match waitpid(-self.pgid, Some(WNOHANG)) {
|
match waitpid(-self.pgid, Some(WNOHANG)) {
|
||||||
Ok(WaitStatus::Exited(_, _)) => finished = finished && true,
|
Ok(WaitStatus::Exited(_, _)) |
|
||||||
Ok(WaitStatus::Signaled(_, _, _)) => finished = finished && true,
|
Ok(WaitStatus::Signaled(_, _, _)) => finished = finished && true,
|
||||||
Ok(_) => finished = false,
|
Ok(_) => finished = false,
|
||||||
Err(_) => break
|
Err(_) => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,14 +207,11 @@ mod imp {
|
||||||
self.terminate();
|
self.terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pause(&self) {
|
pub fn pause(&self) {}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reap(&self) {
|
pub fn reap(&self) {}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn resume(&self) {
|
pub fn resume(&self) {}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn terminate(&self) {
|
pub fn terminate(&self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -318,7 +317,7 @@ mod tests {
|
||||||
let path = file.to_path_buf();
|
let path = file.to_path_buf();
|
||||||
|
|
||||||
let process = spawn(&format!("sleep 20; echo hi > {}", path.to_str().unwrap()),
|
let process = spawn(&format!("sleep 20; echo hi > {}", path.to_str().unwrap()),
|
||||||
vec![]);
|
vec![]);
|
||||||
process.kill();
|
process.kill();
|
||||||
process.wait();
|
process.wait();
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ pub enum Signal {
|
||||||
Terminate,
|
Terminate,
|
||||||
Stop,
|
Stop,
|
||||||
Continue,
|
Continue,
|
||||||
ChildExit
|
ChildExit,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -32,12 +32,13 @@ pub fn install_handler<F>(handler: F)
|
||||||
set_handler(handler);
|
set_handler(handler);
|
||||||
|
|
||||||
// Indicate interest in SIGCHLD by setting a dummy handler
|
// Indicate interest in SIGCHLD by setting a dummy handler
|
||||||
pub extern "C" fn sigchld_handler(_: c_int) {
|
pub extern "C" fn sigchld_handler(_: c_int) {}
|
||||||
}
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let _ = sigaction(SIGCHLD, &SigAction::new(
|
let _ = sigaction(SIGCHLD,
|
||||||
SigHandler::Handler(sigchld_handler), SaFlags::empty(), SigSet::empty()));
|
&SigAction::new(SigHandler::Handler(sigchld_handler),
|
||||||
|
SaFlags::empty(),
|
||||||
|
SigSet::empty()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spawn a thread to catch these signals
|
// Spawn a thread to catch these signals
|
||||||
|
@ -47,12 +48,11 @@ pub fn install_handler<F>(handler: F)
|
||||||
debug!("Received {:?}", raw_signal);
|
debug!("Received {:?}", raw_signal);
|
||||||
|
|
||||||
let sig = match raw_signal {
|
let sig = match raw_signal {
|
||||||
SIGTERM => self::Signal::Terminate,
|
SIGTERM | SIGINT => self::Signal::Terminate,
|
||||||
SIGINT => self::Signal::Terminate,
|
|
||||||
SIGTSTP => self::Signal::Stop,
|
SIGTSTP => self::Signal::Stop,
|
||||||
SIGCONT => self::Signal::Continue,
|
SIGCONT => self::Signal::Continue,
|
||||||
SIGCHLD => self::Signal::ChildExit,
|
SIGCHLD => self::Signal::ChildExit,
|
||||||
_ => unreachable!()
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Invoke closure
|
// Invoke closure
|
||||||
|
@ -60,7 +60,8 @@ pub fn install_handler<F>(handler: F)
|
||||||
|
|
||||||
// Restore default behavior for received signal and unmask it
|
// Restore default behavior for received signal and unmask it
|
||||||
if raw_signal != SIGCHLD {
|
if raw_signal != SIGCHLD {
|
||||||
let default_action = SigAction::new(SigHandler::SigDfl, SaFlags::empty(), SigSet::empty());
|
let default_action =
|
||||||
|
SigAction::new(SigHandler::SigDfl, SaFlags::empty(), SigSet::empty());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let _ = sigaction(raw_signal, &default_action);
|
let _ = sigaction(raw_signal, &default_action);
|
||||||
|
|
Loading…
Reference in New Issue