suppress alot of useless files.

This commit is contained in:
primardj 2024-04-11 20:28:58 +01:00
parent a4ee3033b0
commit 37783dffe7
14 changed files with 7 additions and 238 deletions

View file

@ -4,13 +4,7 @@ pub mod sent_signal;
use crate::status_obj;
pub fn execute(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, services: Vec<String>) -> i32{
println!("execute in exec");
dbg!(svdir_var.clone());
dbg!(svwait_var);
dbg!(verbose);
dbg!(command);
let mut exit_code: i32 = 0;
@ -39,27 +33,9 @@ pub fn execute(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, s
if exit_code < 99 {
exit_code += 1;
}
},
};
// 1. Check if path exists.
//
//let path_to_sv = Path::new(&path);
//if set_current_dir(path_to_sv).is_ok() {
// // Call the change in the service.
// exit_code = sent_signal::sent_signal(exit_code, svwait_var, verbose, command, sv);
//} else {
// println!("fail: {}: unable to change to service directory: file does not exist", sv);
// if exit_code < 99 {
// exit_code += 1;
// }
//}
}
return exit_code
}

View file

@ -1,23 +1,12 @@
//pub mod exec_status;
//pub mod make_exit_code;
//pub mod return_u8_in_u32;
//pub mod return_u8_in_u64;
use crate::status_obj;
//use std::path::Path;
pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_obj::StatusObj) -> i32 {
// Return 0 in case everything worked fine, return 1 if timeout or error.
// Check if supervise/ok exist.
//let supervise_ok = Path::new("supervise/ok");
//if ! supervise_ok.exists() {
// println!("warning: {}: unable to open supervise/ok: file does not exist", sv.clone());
// return make_exit_code::make_exit_code(exit_code);
//}
dbg!(svwait_var);
dbg!(verbose);
// execute command.
if command == "s" {
@ -36,7 +25,6 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
}
println!("{}", status_sv);
return 0;
}
//let service = fs::OpenOptions::new().append(true).open("supervise/control");

View file

@ -1,84 +0,0 @@
mod make_pause_run;
mod make_run_finish;
mod make_term_sig;
mod make_up_down;
mod make_normal_state;
use crate::executor::sent_signal::make_exit_code::make_exit_code;
use crate::executor::sent_signal::return_u8_in_u32::return_u8_in_u32;
use crate::executor::sent_signal::return_u8_in_u64::return_u8_in_u64;
use std::fs;
use std::io::prelude::*;
pub fn exec_status(exit_code: i32, sv: String) -> i32 {
let status_option = fs::OpenOptions::new().read(true).open("supervise/status");
// works this way :
// 20 chars,
// TODO 0 -> 11; time since I don't know when. It is time_sv = 4611686018427387914 + time_unix
// TODO
// TODO seams to be 0 -> 7 time, 7 -> 11 nano seconds..
// 12 -> 15; PID
// 16; PAUSE/RUN
// 17; UP/DOWN
// 18; TERM SIG
// 19; RUN/FINISH
//
// In this version, don't take in account the time. (char 0 -> 11)
if ! status_option.is_ok() {
println!("ERROR, Unable to get supervise/status");
return make_exit_code(exit_code);
}
let mut status = match status_option {
Ok(file) => file,
Err(..) => {
println!("warning: {}: unable to open supervise/status: file does not exist", sv.clone());
return make_exit_code(exit_code);
},
};
let mut contents: Vec<u8> = Vec::new();
let option_size = status.read_to_end(&mut contents);
let size = match option_size {
Ok(size) => size,
Err(..) => {
println!("warning: {}: couldn't read supervise/status", sv.clone());
return make_exit_code(exit_code);
},
};
let time_buf: Vec<u8> = contents[0..8].to_vec();
let uknown_buf: Vec<u8> = contents[8..12].to_vec(); // TODO
let pid_buf: Vec<u8> = contents[12..16].to_vec();
let time = return_u8_in_u64(time_buf); // TODO: correct the unsigned/signed bug.
let pid: u32 = return_u8_in_u32(pid_buf.clone());
let pause_run = make_pause_run::mpr(contents[16]);
let up_down = make_up_down::mud(contents[17]);
let term_sig = make_term_sig::mts(contents[18]);
let run_finish = make_run_finish::mrf(contents[19]);
let normal_state = make_normal_state::mns(contents[19]);
dbg!(contents);
//dbg!(time_buf);
dbg!(pause_run);
dbg!(up_down);
dbg!(term_sig);
if pid != 0 {
println!("{run_finish}{sv}: (pid {pid}) {time}s{normal_state}");
} else {
println!("{run_finish}{sv}: {time}s{normal_state}");
}
return exit_code;
}

View file

@ -1,20 +0,0 @@
use std::path::Path;
pub fn mns(actual_state: u8) -> &'static str {
let down_option = Path::new("down");
if down_option.exists() {
if actual_state == 0 {
return "";
} else {
return ", normally down";
}
} else {
if actual_state == 0 {
return ", normally up";
} else {
return "";
}
}
}

View file

@ -1,9 +0,0 @@
pub fn mpr(pause_run_int: u8) -> &'static str {
if pause_run_int == 0 {
return ""
} else {
return ", paused"
}
}

View file

@ -1,10 +0,0 @@
pub fn mrf(run_finish_int: u8) -> &'static str {
if run_finish_int == 0 {
return "down: "
} else {
return "run: "
}
}

View file

@ -1,10 +0,0 @@
pub fn mts(term_sig_int: u8) -> &'static str {
if term_sig_int == 0 {
return ""
} else {
return ", got TERM"
}
}

View file

@ -1,11 +0,0 @@
pub fn mud(up_down_int: u8) -> &'static str {
if up_down_int == 117 {
return ", want up"
} else {
return ", want down"
}
}

View file

@ -1,9 +0,0 @@
pub fn make_exit_code(exit_code: i32) -> i32 {
if exit_code < 99 {
return exit_code + 1;
} else {
return exit_code;
}
}

View file

@ -1,18 +0,0 @@
pub fn return_u8_in_u32(mut table: Vec<u8>) -> u32 {
// Table make 4 vector u8 in one u32
if table.len() != 4 {
return 0
}
let mut r: u32 = 0;
table.reverse();
for i in table.iter() {
//println!("{}",i);
r = r * 256;
r += <u8 as Into<u32>>::into(*i);
}
return r
}

View file

@ -1,17 +0,0 @@
pub fn return_u8_in_u64(mut table: Vec<u8>) -> u64 {
// Table make 4 vector u8 in one u64
if table.len() != 8 {
return 0
}
let mut r: u64 = 0;
table.reverse();
for i in table.iter() {
//println!("{}",i);
r = r * 256;
r += <u8 as Into<u64>>::into(*i);
}
return r
}

View file

@ -72,7 +72,7 @@ fn phase2(arg: &String) -> String {
pub fn parse_args_1(arg: &String) -> String{
// Get a string
// Return a vect ('first_char', 'length', 'entry_necessary')
// Return the flag.
let ch1 = arg.chars().next().unwrap();
@ -97,15 +97,12 @@ pub fn parse_args_2(arg: &String) -> String{
const POSSIBLE: &'static [&'static str] = &["start", "stop", "reload", "restart", "shutdown", "force-stop", "force-reload", "force-restart", "force-shutdown", "try-restart"];
const CPOSSIBLE: &'static [char] = &['s', 'u', 'd', 'o', 'p', 'c', 'h', 'a', 'i', 'q', '1', '2', 't', 'k'];
for var in POSSIBLE.iter() {
if arg == var {
return var.to_string()
}
}
let ch1 = arg.chars().next().unwrap();
@ -115,7 +112,6 @@ pub fn parse_args_2(arg: &String) -> String{
}
}
return "INVALID".to_string()

View file

@ -106,14 +106,14 @@ impl StatusObj {
pub fn get_status_string(&mut self) -> String {
//dbg!(&self.svname);
dbg!(&self.svpath);
dbg!(self.time);
//dbg!(self.time);
dbg!(self.nano_seconds);
//dbg!(self.pid);
dbg!(self.pause_run);
dbg!(self.up_down);
dbg!(self.term_sig);
//dbg!(self.run_finish);
dbg!(self.down);
//dbg!(self.down);
dbg!(self.log);
// TODO

View file

@ -39,35 +39,32 @@ pub fn return_reverse_u8_in_u32(mut table: Vec<u8>) -> u32 {
let mut r: u32 = 0;
table.reverse();
for i in table.iter() {
//println!("{}",i);
r = r * 256;
r += <u8 as Into<u32>>::into(*i);
}
return r
}
pub fn return_u8_in_u32(mut table: Vec<u8>) -> u32 {
pub fn return_u8_in_u32(table: Vec<u8>) -> u32 {
// Table make 4 values u8 in one u32
if table.len() != 4 {
return 0
}
let mut r: u32 = 0;
for i in table.iter() {
//println!("{}",i);
r = r * 256;
r += <u8 as Into<u32>>::into(*i);
}
return r
}
pub fn return_u8_in_u64(mut table: Vec<u8>) -> u64 {
pub fn return_u8_in_u64(table: Vec<u8>) -> u64 {
// Table make 8 values u8 in one u64
if table.len() != 8 {
return 0
}
let mut r: u64 = 0;
for i in table.iter() {
//println!("{}",i);
r = r * 256;
r += <u8 as Into<u64>>::into(*i);
}