Remove unnecessary code

This commit is contained in:
Alex Kotov 2021-12-05 21:52:30 +05:00
parent 9443fec3f4
commit 3c97b8ee74
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -22,25 +22,12 @@ impl TaskConfig {
pub fn new<Exe: Into<String>>(exe: Exe) -> Self {
Self { exe: exe.into() }
}
pub fn exe(&self) -> &String {
&self.exe
}
}
impl TaskInfo {
pub fn new(config: TaskConfig, pid: libc::pid_t) -> Self {
Self { config, pid }
}
#[allow(dead_code)]
pub fn config(&self) -> &TaskConfig {
&self.config
}
pub fn pid(&self) -> libc::pid_t {
self.pid
}
}
impl TaskResult {
@ -48,11 +35,6 @@ impl TaskResult {
Self { info, status }
}
#[allow(dead_code)]
pub fn info(&self) -> &TaskInfo {
&self.info
}
pub fn status(&self) -> i32 {
self.status
}
@ -71,7 +53,7 @@ pub trait Task: Debug + Sized {
}
if pid == 0 {
let arg0 = CString::new(config.exe().as_bytes()).unwrap();
let arg0 = CString::new(config.exe.as_bytes()).unwrap();
let args = vec![arg0.as_ptr(), std::ptr::null()];
libc::execvp(arg0.as_ptr(), args.as_ptr());
libc::exit(libc::EXIT_FAILURE);
@ -84,7 +66,7 @@ pub trait Task: Debug + Sized {
fn wait(self) -> TaskResult {
unsafe {
let status: i32 = 0;
libc::waitpid(self.info().pid(), status as *mut i32, 0);
libc::waitpid(self.info().pid, status as *mut i32, 0);
let status = libc::WEXITSTATUS(status);
TaskResult::new(self.info().clone(), status)
}
@ -92,9 +74,9 @@ pub trait Task: Debug + Sized {
fn terminate(self) -> TaskResult {
unsafe {
libc::kill(self.info().pid(), libc::SIGKILL);
libc::kill(self.info().pid, libc::SIGKILL);
let status: i32 = 0;
libc::waitpid(self.info().pid(), status as *mut i32, 0);
libc::waitpid(self.info().pid, status as *mut i32, 0);
let status = libc::WEXITSTATUS(status);
TaskResult::new(self.info().clone(), status)
}