implem_command #9

Merged
statzitz merged 13 commits from implem_command into main 2024-04-18 01:30:48 +02:00
3 changed files with 98 additions and 5 deletions
Showing only changes of commit 32acba1e7a - Show all commits

View file

@ -47,7 +47,13 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
return misc::noexcept_verbose(sv.sent_signal(b"1"), verbose, sv);
},
"2" => {
return misc::noexcept_verbose(sv.sent_signal(b"1"), verbose, sv);
return misc::noexcept_verbose(sv.sent_signal(b"2"), verbose, sv);
},
"t" => {
return misc::term_verbose(sv.sent_signal(b"t"), false, verbose, svwait_var, sv);
},
"k" => {
return misc::kill_verbose(sv.sent_signal(b"k"), verbose, svwait_var, sv);
},
other => {
println!("Error, command {} not implemented.", other); // TODO : Put the real error

View file

@ -28,6 +28,7 @@ pub fn run_verbose(sent_signal: bool, expected: bool, verbose: i8, svwait_var: i
// if the excepted is true, wait for the service to run.
// If the excepted is false, wait for the service to down.
if sent_signal && verbose == 1 {
sleep(Duration::from_secs_f32(0.0005));
let mut time_wait = 0;
loop {
let status = sv.update_status();
@ -38,12 +39,12 @@ pub fn run_verbose(sent_signal: bool, expected: bool, verbose: i8, svwait_var: i
println!("ok: {}", sv.get_status_string());
return 0
}
if time_wait >= svwait_var {
if time_wait >= svwait_var*2 {
println!("timeout: {}", sv.get_status_string());
return 1
}
time_wait += 1;
sleep(Duration::from_secs(1));
sleep(Duration::from_secs_f32(0.5));
}
} else if sent_signal && verbose == 0 {
return 0
@ -57,6 +58,7 @@ pub fn pause_verbose(sent_signal: bool, expected: bool, verbose: i8, svwait_var:
// if the excepted is true, wait for the service to pause.
// if the excepted is false, wait for the service to continue.
if sent_signal && verbose == 1 {
sleep(Duration::from_secs_f32(0.0005));
let mut time_wait = 0;
loop {
let status = sv.update_status();
@ -67,12 +69,12 @@ pub fn pause_verbose(sent_signal: bool, expected: bool, verbose: i8, svwait_var:
println!("ok: {}", sv.get_status_string());
return 0
}
if time_wait >= svwait_var {
if time_wait >= svwait_var*2 {
println!("timeout: {}", sv.get_status_string());
return 1
}
time_wait += 1;
sleep(Duration::from_secs(1));
sleep(Duration::from_secs_f32(0.5));
}
} else if sent_signal && verbose == 0 {
return 0
@ -82,9 +84,73 @@ pub fn pause_verbose(sent_signal: bool, expected: bool, verbose: i8, svwait_var:
}
}
pub fn term_verbose(sent_signal: bool, expected: bool, verbose: i8, svwait_var: i32, mut sv: status_obj::StatusObj) -> i32 {
// if the excepted is true, wait for the service to get term signal.
// if the excepted is false, wait for the service to interpret the term signal.
if sent_signal && verbose == 1 {
sleep(Duration::from_secs_f32(0.0005));
let mut time_wait = 0;
loop {
let status = sv.update_status();
if status == 1 {
return 1;
}
if sv.is_term() == expected {
println!("ok: {}", sv.get_status_string());
return 0
}
if time_wait >= svwait_var*2 {
println!("timeout: {}", sv.get_status_string());
return 1
}
time_wait += 1;
sleep(Duration::from_secs_f32(0.5));
}
} else if sent_signal && verbose == 0 {
return 0
} else {
// Case sent_signal != true.
return 1
}
}
pub fn kill_verbose(sent_signal: bool, verbose: i8, svwait_var: i32, mut sv: status_obj::StatusObj) -> i32 {
if sent_signal && verbose == 1 {
sleep(Duration::from_secs_f32(0.0005));
let mut time_wait = 0;
if ! sv.get_run_finish() {
println!("ok: {}", sv.get_status_string());
return 0;
}
let pid = sv.get_pid();
let time = sv.get_time();
loop {
let status = sv.update_status();
if status == 1 {
return 1;
}
if pid != sv.get_pid() || time > sv.get_time() {
println!("ok: {}", sv.get_status_string());
return 0
}
if time_wait >= svwait_var*2 {
println!("timeout: {}", sv.get_status_string());
return 1
}
time_wait += 1;
sleep(Duration::from_secs_f32(0.5));
}
} else if sent_signal && verbose == 0 {
return 0
} else {
// Case sent_signal != true.
return 1
}
}
pub fn noexcept_verbose(sent_signal: bool, verbose: i8, mut sv: status_obj::StatusObj) -> i32 {
if sent_signal && verbose == 1 {
sleep(Duration::from_secs_f32(0.0005));
let status = sv.update_status();
if status == 1 {
return 1;

View file

@ -213,6 +213,7 @@ impl StatusObj {
term_string = "";
}
let time_repaired: u64 = self.time - 4611686018427387914;
let sys_time_result = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH);
let sys_time = match sys_time_result {
@ -249,6 +250,14 @@ impl StatusObj {
}
}
pub fn is_term(&mut self) -> bool {
if self.term_sig == true {
return true
} else {
return false
}
}
pub fn get_name(&mut self) -> String {
return self.svname.clone();
}
@ -261,6 +270,18 @@ impl StatusObj {
return self.log;
}
pub fn get_pid(&mut self) -> u32 {
return self.pid;
}
pub fn get_time(&mut self) -> u64 {
return self.time;
}
pub fn get_run_finish(&mut self) -> bool {
return self.run_finish;
}
pub fn get_obj_log(&mut self) -> Option<StatusObj> {
return StatusObj::new(self.svpath.clone() + "/log", "log".to_string());
}