Remove unnecessary code
This commit is contained in:
parent
9443fec3f4
commit
3c97b8ee74
26
src/task.rs
26
src/task.rs
|
@ -22,25 +22,12 @@ impl TaskConfig {
|
||||||
pub fn new<Exe: Into<String>>(exe: Exe) -> Self {
|
pub fn new<Exe: Into<String>>(exe: Exe) -> Self {
|
||||||
Self { exe: exe.into() }
|
Self { exe: exe.into() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exe(&self) -> &String {
|
|
||||||
&self.exe
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TaskInfo {
|
impl TaskInfo {
|
||||||
pub fn new(config: TaskConfig, pid: libc::pid_t) -> Self {
|
pub fn new(config: TaskConfig, pid: libc::pid_t) -> Self {
|
||||||
Self { config, pid }
|
Self { config, pid }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn config(&self) -> &TaskConfig {
|
|
||||||
&self.config
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pid(&self) -> libc::pid_t {
|
|
||||||
self.pid
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TaskResult {
|
impl TaskResult {
|
||||||
|
@ -48,11 +35,6 @@ impl TaskResult {
|
||||||
Self { info, status }
|
Self { info, status }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn info(&self) -> &TaskInfo {
|
|
||||||
&self.info
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn status(&self) -> i32 {
|
pub fn status(&self) -> i32 {
|
||||||
self.status
|
self.status
|
||||||
}
|
}
|
||||||
|
@ -71,7 +53,7 @@ pub trait Task: Debug + Sized {
|
||||||
}
|
}
|
||||||
|
|
||||||
if pid == 0 {
|
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()];
|
let args = vec![arg0.as_ptr(), std::ptr::null()];
|
||||||
libc::execvp(arg0.as_ptr(), args.as_ptr());
|
libc::execvp(arg0.as_ptr(), args.as_ptr());
|
||||||
libc::exit(libc::EXIT_FAILURE);
|
libc::exit(libc::EXIT_FAILURE);
|
||||||
|
@ -84,7 +66,7 @@ pub trait Task: Debug + Sized {
|
||||||
fn wait(self) -> TaskResult {
|
fn wait(self) -> TaskResult {
|
||||||
unsafe {
|
unsafe {
|
||||||
let status: i32 = 0;
|
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);
|
let status = libc::WEXITSTATUS(status);
|
||||||
TaskResult::new(self.info().clone(), status)
|
TaskResult::new(self.info().clone(), status)
|
||||||
}
|
}
|
||||||
|
@ -92,9 +74,9 @@ pub trait Task: Debug + Sized {
|
||||||
|
|
||||||
fn terminate(self) -> TaskResult {
|
fn terminate(self) -> TaskResult {
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::kill(self.info().pid(), libc::SIGKILL);
|
libc::kill(self.info().pid, libc::SIGKILL);
|
||||||
let status: i32 = 0;
|
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);
|
let status = libc::WEXITSTATUS(status);
|
||||||
TaskResult::new(self.info().clone(), status)
|
TaskResult::new(self.info().clone(), status)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue