1
Fork 0

uefi: process Implement inherit

Only tested in 2 levels right now. Need args support for 3 levels

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
This commit is contained in:
Ayush Singh 2024-03-29 19:07:46 +05:30 committed by Ayush Singh
parent 725376567a
commit d44b3fb120
No known key found for this signature in database
GPG key ID: 05CEF5C789E55A74

View file

@ -23,8 +23,8 @@ use super::helpers;
pub struct Command { pub struct Command {
prog: OsString, prog: OsString,
stdout: Option<uefi_command_internal::PipeProtocol>, stdout: Option<Stdio>,
stderr: Option<uefi_command_internal::PipeProtocol>, stderr: Option<Stdio>,
} }
// passed back to std::process with the pipes connected to the child, if any // passed back to std::process with the pipes connected to the child, if any
@ -65,19 +65,11 @@ impl Command {
} }
pub fn stdout(&mut self, stdout: Stdio) { pub fn stdout(&mut self, stdout: Stdio) {
self.stdout = match stdout { self.stdout = Some(stdout);
Stdio::MakePipe => Some(uefi_command_internal::PipeProtocol::new()),
Stdio::Null => Some(uefi_command_internal::PipeProtocol::null()),
_ => None,
};
} }
pub fn stderr(&mut self, stderr: Stdio) { pub fn stderr(&mut self, stderr: Stdio) {
self.stderr = match stderr { self.stderr = Some(stderr);
Stdio::MakePipe => Some(uefi_command_internal::PipeProtocol::new()),
Stdio::Null => Some(uefi_command_internal::PipeProtocol::null()),
_ => None,
};
} }
pub fn get_program(&self) -> &OsStr { pub fn get_program(&self) -> &OsStr {
@ -104,31 +96,56 @@ impl Command {
unsupported() 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>)> { pub fn output(&mut self) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
let mut cmd = uefi_command_internal::Command::load_image(&self.prog)?; 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() { 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( None => helpers::Protocol::create(
uefi_command_internal::PipeProtocol::new(), uefi_command_internal::PipeProtocol::new(),
simple_text_output::PROTOCOL_GUID, 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() { 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( None => helpers::Protocol::create(
uefi_command_internal::PipeProtocol::new(), uefi_command_internal::PipeProtocol::new(),
simple_text_output::PROTOCOL_GUID, simple_text_output::PROTOCOL_GUID,
), )
.map(Some),
}?; }?;
cmd.stdout_init(stdout)?; if let Some(stdout) = stdout {
cmd.stderr_init(stderr)?; cmd.stdout_init(stdout)?;
}
if let Some(stderr) = stderr {
cmd.stderr_init(stderr)?;
}
let stat = cmd.start_image()?; let stat = cmd.start_image()?;
let stdout = cmd.stdout()?; let stdout = cmd.stdout()?;
let stderr = cmd.stderr()?; let stderr = cmd.stderr()?;