implem sent_signal and command u
This commit is contained in:
parent
f2a9af6168
commit
c0ae3d3aed
3 changed files with 54 additions and 0 deletions
|
@ -27,6 +27,17 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
|
|||
return 0;
|
||||
}
|
||||
|
||||
if command == "u" {
|
||||
// case where command is up
|
||||
if sv.sent_signal(b"u") == true {
|
||||
println!("Tout c bien passé");
|
||||
return 0;
|
||||
} else {
|
||||
println!("Ko Error panic tout ce que tu veux.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
//let service = fs::OpenOptions::new().append(true).open("supervise/control");
|
||||
|
||||
//if ! service.is_ok() {
|
||||
|
|
|
@ -173,6 +173,10 @@ impl StatusObj {
|
|||
return return_string;
|
||||
}
|
||||
|
||||
pub fn sent_signal(&mut self, signal: &[u8]) -> bool {
|
||||
return misc::sent_signal(signal);
|
||||
}
|
||||
|
||||
pub fn get_log(&mut self) -> bool {
|
||||
return self.log;
|
||||
}
|
||||
|
@ -180,5 +184,6 @@ impl StatusObj {
|
|||
pub fn get_obj_log(&mut self) -> Option<StatusObj> {
|
||||
return StatusObj::new(self.svpath.clone() + "/log", "log".to_string());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
use tokio::net::unix::pipe;
|
||||
use tokio::runtime::Runtime;
|
||||
use std::io::ErrorKind;
|
||||
|
||||
pub fn make_pause_run(pr_int: u8) -> bool {
|
||||
if pr_int == 0 {
|
||||
|
@ -94,3 +95,40 @@ pub fn check_fifo(sv: String, path: &str) -> bool {
|
|||
},
|
||||
};
|
||||
}
|
||||
|
||||
pub fn sent_signal(signal: &[u8]) -> bool {
|
||||
// sent the char to supervise/control.
|
||||
// return true in case everything worked fine, false if there was any errors.
|
||||
let rt = Runtime::new().unwrap();
|
||||
let _guard = rt.enter();
|
||||
|
||||
let sender = pipe::OpenOptions::new().open_sender("supervise/control");
|
||||
match sender {
|
||||
Ok(tx) => {
|
||||
loop {
|
||||
match tx.try_write(signal) {
|
||||
Ok(..) => {
|
||||
println!("write successful");
|
||||
return true;
|
||||
},
|
||||
Err(e) if e.kind() == ErrorKind::WouldBlock => {
|
||||
continue;
|
||||
},
|
||||
Err(e) => {
|
||||
dbg!(e);
|
||||
println!("Error while trying to sent command");
|
||||
return false;
|
||||
},
|
||||
}
|
||||
};
|
||||
},
|
||||
Err(e) if e.raw_os_error() == Some(libc::ENXIO) => {
|
||||
println!("fail: sv: runsv not running");
|
||||
return false;
|
||||
},
|
||||
Err(..) => {
|
||||
println!("warning: sv: unable to open path: file does not exist");
|
||||
return false;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue