add o command and solve some littles problems with prints.

This commit is contained in:
primardj 2024-04-15 23:09:15 +01:00
parent cb96b16438
commit d5064ae281
2 changed files with 42 additions and 18 deletions

View file

@ -21,23 +21,7 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
// case where command is up // case where command is up
if sv.sent_signal(b"u") { if sv.sent_signal(b"u") {
if verbose == 1 { if verbose == 1 {
loop { return misc::run_verbose(svwait_var, sv);
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));
}
} else { } else {
return 0; return 0;
} }
@ -56,7 +40,7 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
return 1; return 1;
} }
if sv.is_up() == false { if sv.is_up() == false {
misc::print_status(sv); println!("{}", sv.get_status_string());
return 0 return 0
} }
if time_wait >= svwait_var { 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."); println!("Error, command not implemented.");
return 1; return 1;
} }

View file

@ -1,6 +1,9 @@
use crate::status_obj; use crate::status_obj;
use std::thread::sleep;
use std::time::Duration;
pub fn print_status(mut sv: status_obj::StatusObj) -> i32 { pub fn print_status(mut sv: status_obj::StatusObj) -> i32 {
// The status code is the one who will be // The status code is the one who will be
let mut status_sv = sv.get_status_string(); 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); println!("{}", status_sv);
return 0; 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));
}
}