diff options
| author | Ayush Singh <ayushdevel1325@gmail.com> | 2024-03-29 19:07:46 +0530 |
|---|---|---|
| committer | Ayush Singh <ayush@beagleboard.org> | 2024-07-19 17:43:45 +0530 |
| commit | d44b3fb120a05d4cd9d663b434bea56e65ef2df2 (patch) | |
| tree | 1e1259c818316ab99c24e623ae00306f9645a566 | |
| parent | 725376567ae0e2b75574bbda68d191ebd3a4ce68 (diff) | |
| download | rust-d44b3fb120a05d4cd9d663b434bea56e65ef2df2.tar.gz rust-d44b3fb120a05d4cd9d663b434bea56e65ef2df2.zip | |
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>
| -rw-r--r-- | library/std/src/sys/pal/uefi/process.rs | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/library/std/src/sys/pal/uefi/process.rs b/library/std/src/sys/pal/uefi/process.rs index fc96f382650..ed25ad81bbd 100644 --- a/library/std/src/sys/pal/uefi/process.rs +++ b/library/std/src/sys/pal/uefi/process.rs @@ -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 @@ -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 { @@ -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()?; |
