implem_command #9
2 changed files with 42 additions and 18 deletions
|
@ -21,23 +21,7 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
|
|||
// case where command is up
|
||||
if sv.sent_signal(b"u") {
|
||||
if verbose == 1 {
|
||||
loop {
|
||||
let status = sv.update_status();
|
||||
if status == 1 {
|
||||
return 1;
|
||||
}
|
||||
if sv.is_up() == true {
|
||||
misc::print_status(sv);
|
||||
return 0
|
||||
}
|
||||
if time_wait >= svwait_var {
|
||||
println!("timeout: {}", sv.get_status_string());
|
||||
return 1
|
||||
}
|
||||
|
||||
time_wait += 1;
|
||||
sleep(Duration::from_secs(1));
|
||||
}
|
||||
return misc::run_verbose(svwait_var, sv);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
@ -56,7 +40,7 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
|
|||
return 1;
|
||||
}
|
||||
if sv.is_up() == false {
|
||||
misc::print_status(sv);
|
||||
println!("{}", sv.get_status_string());
|
||||
return 0
|
||||
}
|
||||
if time_wait >= svwait_var {
|
||||
|
@ -75,8 +59,22 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
|
|||
}
|
||||
}
|
||||
|
||||
if command == "o" {
|
||||
// case where command is run once.
|
||||
if sv.sent_signal(b"o") {
|
||||
if verbose == 1 {
|
||||
return misc::run_verbose(svwait_var, sv);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
println!("Error, command not implemented.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
|
||||
use crate::status_obj;
|
||||
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn print_status(mut sv: status_obj::StatusObj) -> i32 {
|
||||
// The status code is the one who will be
|
||||
let mut status_sv = sv.get_status_string();
|
||||
|
@ -19,3 +22,26 @@ pub fn print_status(mut sv: status_obj::StatusObj) -> i32 {
|
|||
println!("{}", status_sv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
pub fn run_verbose(svwait_var: i32, mut sv: status_obj::StatusObj) -> i32 {
|
||||
let mut time_wait = 0;
|
||||
loop {
|
||||
let status = sv.update_status();
|
||||
if status == 1 {
|
||||
return 1;
|
||||
}
|
||||
if sv.is_up() == true {
|
||||
println!("ok: {}", sv.get_status_string());
|
||||
return 0
|
||||
}
|
||||
if time_wait >= svwait_var {
|
||||
println!("timeout: {}", sv.get_status_string());
|
||||
return 1
|
||||
}
|
||||
|
||||
time_wait += 1;
|
||||
sleep(Duration::from_secs(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue