Skip to content

Commit

Permalink
Implement Pipeline.find_command
Browse files Browse the repository at this point in the history
  • Loading branch information
guilload committed Jun 27, 2017
1 parent a28e973 commit 4fcd86e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,25 @@ impl Pipeline {
Ok(())
}

pub fn find_command(&mut self, pid: libc::pid_t) -> Option<&mut Command> {
self.commands.iter_mut().find(|c| c.pid == pid)
}

pub fn is_completed(&self) -> bool {
self.commands.iter().all(|c| c.is_completed())
}

pub fn is_suspended(&self) -> bool {
self.commands.iter().all(|c| c.is_suspended())
}

pub fn wait(&mut self) -> Result<(), nix::Error> {
while !self.is_completed() { // FIXME
while !self.is_completed() {
let status = waitpid(-1 * self.pgid, Some(WUNTRACED))?;

match status {
WaitStatus::Exited(pid, _) => self.commands.iter_mut().find(|c| c.pid == pid).unwrap().status(Status::Completed), // FIXME
WaitStatus::Stopped(pid, _) => self.commands.iter_mut().find(|c| c.pid == pid).unwrap().status(Status::Suspended),
WaitStatus::Exited(pid, _) => self.find_command(pid).unwrap().status(Status::Completed),
WaitStatus::Stopped(pid, _) => self.find_command(pid).unwrap().status(Status::Suspended),
_ => panic!("unimplemented!"),
};
}
Expand Down

0 comments on commit 4fcd86e

Please sign in to comment.