Skip to content

Commit

Permalink
uefi: process Implement inherit
Browse files Browse the repository at this point in the history
Only tested in 2 levels right now. Need args support for 3 levels

Signed-off-by: Ayush Singh <[email protected]>
  • Loading branch information
Ayush1325 committed Jul 19, 2024
1 parent 24a9582 commit 1991fe3
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions std/src/sys/pal/uefi/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use super::helpers;

pub struct Command {
prog: OsString,
stdout: Option<uefi_command_internal::PipeProtocol>,
stderr: Option<uefi_command_internal::PipeProtocol>,
stdout: Option<Stdio>,
stderr: Option<Stdio>,
}

// passed back to std::process with the pipes connected to the child, if any
Expand Down Expand Up @@ -65,19 +65,11 @@ impl Command {
}

pub fn stdout(&mut self, stdout: Stdio) {
self.stdout = match stdout {
Stdio::MakePipe => Some(uefi_command_internal::PipeProtocol::new()),
Stdio::Null => Some(uefi_command_internal::PipeProtocol::null()),
_ => None,
};
self.stdout = Some(stdout);
}

pub fn stderr(&mut self, stderr: Stdio) {
self.stderr = match stderr {
Stdio::MakePipe => Some(uefi_command_internal::PipeProtocol::new()),
Stdio::Null => Some(uefi_command_internal::PipeProtocol::null()),
_ => None,
};
self.stderr = Some(stderr);
}

pub fn get_program(&self) -> &OsStr {
Expand All @@ -104,31 +96,56 @@ impl Command {
unsupported()
}

fn create_pipe(
s: Stdio,
) -> io::Result<Option<helpers::Protocol<uefi_command_internal::PipeProtocol>>> {
match s {
Stdio::MakePipe => helpers::Protocol::create(
uefi_command_internal::PipeProtocol::new(),
simple_text_output::PROTOCOL_GUID,
)
.map(Some),
Stdio::Null => helpers::Protocol::create(
uefi_command_internal::PipeProtocol::null(),
simple_text_output::PROTOCOL_GUID,
)
.map(Some),
Stdio::Inherit => Ok(None),
}
}

pub fn output(&mut self) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
let mut cmd = uefi_command_internal::Command::load_image(&self.prog)?;

let stdout: helpers::Protocol<uefi_command_internal::PipeProtocol> =
let stdout: Option<helpers::Protocol<uefi_command_internal::PipeProtocol>> =
match self.stdout.take() {
Some(s) => helpers::Protocol::create(s, simple_text_output::PROTOCOL_GUID),
Some(s) => Self::create_pipe(s),
None => helpers::Protocol::create(
uefi_command_internal::PipeProtocol::new(),
simple_text_output::PROTOCOL_GUID,
),
)
.map(Some),
}?;

let stderr: helpers::Protocol<uefi_command_internal::PipeProtocol> =
let stderr: Option<helpers::Protocol<uefi_command_internal::PipeProtocol>> =
match self.stderr.take() {
Some(s) => helpers::Protocol::create(s, simple_text_output::PROTOCOL_GUID),
Some(s) => Self::create_pipe(s),
None => helpers::Protocol::create(
uefi_command_internal::PipeProtocol::new(),
simple_text_output::PROTOCOL_GUID,
),
)
.map(Some),
}?;

cmd.stdout_init(stdout)?;
cmd.stderr_init(stderr)?;
if let Some(stdout) = stdout {
cmd.stdout_init(stdout)?;
}
if let Some(stderr) = stderr {
cmd.stderr_init(stderr)?;
}

let stat = cmd.start_image()?;

let stdout = cmd.stdout()?;
let stderr = cmd.stderr()?;

Expand Down

0 comments on commit 1991fe3

Please sign in to comment.