other smalls optimisations.

This commit is contained in:
primardj 2024-04-15 23:38:24 +01:00
parent 3f57120e53
commit 14b762520f
2 changed files with 26 additions and 45 deletions

View file

@ -13,39 +13,15 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
},
"u" => {
// case where command is up
if sv.sent_signal(b"u") {
if verbose == 1 {
return misc::run_verbose(true, svwait_var, sv);
} else {
return 0;
}
} else {
return 1;
}
return misc::run_verbose(sv.sent_signal(b"u"), true, verbose, svwait_var, sv);
},
"d" => {
// case where command is up
if sv.sent_signal(b"d") {
if verbose == 1 {
return misc::run_verbose(false, svwait_var, sv);
} else {
return 0;
}
} else {
return 1;
}
return misc::run_verbose(sv.sent_signal(b"d"), false, verbose, svwait_var, sv);
},
"o" => {
// case where command is run once.
if sv.sent_signal(b"o") {
if verbose == 1 {
return misc::run_verbose(true, svwait_var, sv);
} else {
return 0;
}
} else {
return 1;
}
return misc::run_verbose(sv.sent_signal(b"o"), true, verbose, svwait_var, sv);
},
other => {
println!("Error, command {} not implemented.", other); // TODO : Put the real error

View file

@ -24,9 +24,10 @@ pub fn print_status(mut sv: status_obj::StatusObj) -> i32 {
}
pub fn run_verbose(state: bool, svwait_var: i32, mut sv: status_obj::StatusObj) -> i32 {
pub fn run_verbose(sent_signal: bool, state: bool, verbose: i8, svwait_var: i32, mut sv: status_obj::StatusObj) -> i32 {
// if the state is true, wait for the service to run.
// If the state is false, wait for the service to down.
if sent_signal && verbose == 1 {
let mut time_wait = 0;
loop {
let status = sv.update_status();
@ -41,9 +42,13 @@ pub fn run_verbose(state: bool, svwait_var: i32, mut sv: status_obj::StatusObj)
println!("timeout: {}", sv.get_status_string());
return 1
}
time_wait += 1;
sleep(Duration::from_secs(1));
}
} else if sent_signal && verbose == 0 {
return 0
} else {
// Case sent_signal != true.
return 1
}
}