Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 36a0e1e

Browse files
committedJul 19, 2024
uefi: process: Add stderr support
Implement stderr support in similar fashion. Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
1 parent b712e74 commit 36a0e1e

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed
 

‎std/src/sys/pal/uefi/process.rs

+34-2
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,15 @@ impl Command {
9292

9393
pub fn output(&mut self) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
9494
let mut cmd = uefi_command_internal::Command::load_image(&self.prog)?;
95+
9596
cmd.stdout_init()?;
97+
cmd.stderr_init()?;
98+
9699
let stat = cmd.start_image()?;
97100
let stdout = cmd.stdout()?;
98-
Ok((ExitStatus(stat), stdout, Vec::new()))
101+
let stderr = cmd.stderr()?;
102+
103+
Ok((ExitStatus(stat), stdout, stderr))
99104
}
100105
}
101106

@@ -263,6 +268,7 @@ mod uefi_command_internal {
263268
pub struct Command {
264269
handle: NonNull<crate::ffi::c_void>,
265270
stdout: Option<helpers::Protocol<PipeProtocol>>,
271+
stderr: Option<helpers::Protocol<PipeProtocol>>,
266272
st: Box<r_efi::efi::SystemTable>,
267273
}
268274

@@ -271,7 +277,7 @@ mod uefi_command_internal {
271277
handle: NonNull<crate::ffi::c_void>,
272278
st: Box<r_efi::efi::SystemTable>,
273279
) -> Self {
274-
Self { handle, stdout: None, st }
280+
Self { handle, stdout: None, stderr: None, st }
275281
}
276282

277283
pub fn load_image(p: &OsStr) -> io::Result<Self> {
@@ -349,6 +355,19 @@ mod uefi_command_internal {
349355
Ok(())
350356
}
351357

358+
pub fn stderr_init(&mut self) -> io::Result<()> {
359+
let mut protocol =
360+
helpers::Protocol::create(PipeProtocol::new(), simple_text_output::PROTOCOL_GUID)?;
361+
362+
self.st.standard_error_handle = protocol.handle().as_ptr();
363+
self.st.std_err =
364+
protocol.as_mut() as *mut PipeProtocol as *mut simple_text_output::Protocol;
365+
366+
self.stderr = Some(protocol);
367+
368+
Ok(())
369+
}
370+
352371
pub fn stdout(&self) -> io::Result<Vec<u8>> {
353372
if let Some(stdout) = &self.stdout {
354373
stdout
@@ -361,6 +380,19 @@ mod uefi_command_internal {
361380
Err(const_io_error!(io::ErrorKind::NotFound, "stdout not found"))
362381
}
363382
}
383+
384+
pub fn stderr(&self) -> io::Result<Vec<u8>> {
385+
if let Some(stderr) = &self.stderr {
386+
stderr
387+
.as_ref()
388+
.utf8()
389+
.into_string()
390+
.map_err(|_| const_io_error!(io::ErrorKind::Other, "utf8 conversion failed"))
391+
.map(Into::into)
392+
} else {
393+
Err(const_io_error!(io::ErrorKind::NotFound, "stdout not found"))
394+
}
395+
}
364396
}
365397

366398
impl Drop for Command {

0 commit comments

Comments
 (0)
Failed to load comments.