diff --git a/01_phase_rust_src/sv-rustit/src/executor/sent_signal.rs b/01_phase_rust_src/sv-rustit/src/executor/sent_signal.rs index 1e1e1f6..9f8e344 100644 --- a/01_phase_rust_src/sv-rustit/src/executor/sent_signal.rs +++ b/01_phase_rust_src/sv-rustit/src/executor/sent_signal.rs @@ -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 diff --git a/01_phase_rust_src/sv-rustit/src/executor/sent_signal/misc.rs b/01_phase_rust_src/sv-rustit/src/executor/sent_signal/misc.rs index 98c80ef..b3883b0 100644 --- a/01_phase_rust_src/sv-rustit/src/executor/sent_signal/misc.rs +++ b/01_phase_rust_src/sv-rustit/src/executor/sent_signal/misc.rs @@ -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 false, wait for the service to down. - let mut time_wait = 0; - loop { - let status = sv.update_status(); - if status == 1 { - return 1; + if sent_signal && verbose == 1 { + let mut time_wait = 0; + loop { + let status = sv.update_status(); + 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 { - 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)); + } else if sent_signal && verbose == 0 { + return 0 + } else { + // Case sent_signal != true. + return 1 } - }