implem_command #9

Merged
statzitz merged 13 commits from implem_command into main 2024-04-18 01:30:48 +02:00
2 changed files with 26 additions and 45 deletions
Showing only changes of commit 14b762520f - Show all commits

View file

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

View file

@ -24,26 +24,31 @@ 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 true, wait for the service to run.
// If the state is false, wait for the service to down. // If the state is false, wait for the service to down.
let mut time_wait = 0; if sent_signal && verbose == 1 {
loop { let mut time_wait = 0;
let status = sv.update_status(); loop {
if status == 1 { let status = sv.update_status();
return 1; if status == 1 {
return 1;
}
if sv.is_up() == state {
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));
} }
if sv.is_up() == state { } else if sent_signal && verbose == 0 {
println!("ok: {}", sv.get_status_string()); return 0
return 0 } else {
} // Case sent_signal != true.
if time_wait >= svwait_var { return 1
println!("timeout: {}", sv.get_status_string());
return 1
}
time_wait += 1;
sleep(Duration::from_secs(1));
} }
} }