Skip to content

Commit 753a452

Browse files
Rollup merge of rust-lang#155826 - devnexen:uefi_stdio_fix, r=jhpratt
std::process: uefi: avoid panicking in Stdio From impls. map io::Stdout/Stderr to Stdio::Inherit and File to a new InheritFile variant returning io::Error from output() instead of aborting.
2 parents eec911e + 57ccc0c commit 753a452

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

library/std/src/sys/process/uefi.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ pub struct Command {
2727
env: CommandEnv,
2828
}
2929

30-
#[derive(Copy, Clone, Debug)]
30+
#[derive(Debug)]
3131
pub enum Stdio {
3232
Inherit,
3333
Null,
3434
MakePipe,
35+
#[allow(dead_code)] // This variant exists only for the Debug impl
36+
InheritFile(File),
3537
}
3638

3739
impl Command {
@@ -120,6 +122,7 @@ impl Command {
120122
)
121123
}
122124
.map(Some),
125+
Stdio::InheritFile(_) => Err(unsupported()?),
123126
Stdio::Inherit => Ok(None),
124127
}
125128
}
@@ -135,6 +138,7 @@ impl Command {
135138
)
136139
}
137140
.map(Some),
141+
Stdio::InheritFile(_) => Err(unsupported()?),
138142
Stdio::Inherit => Ok(None),
139143
Stdio::MakePipe => unsupported(),
140144
}
@@ -153,7 +157,7 @@ pub fn output(command: &mut Command) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>
153157
}
154158

155159
// Setup Stdout
156-
let stdout = command.stdout.unwrap_or(Stdio::MakePipe);
160+
let stdout = command.stdout.take().unwrap_or(Stdio::MakePipe);
157161
let stdout = Command::create_pipe(stdout)?;
158162
if let Some(con) = stdout {
159163
cmd.stdout_init(con)
@@ -162,7 +166,7 @@ pub fn output(command: &mut Command) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>
162166
};
163167

164168
// Setup Stderr
165-
let stderr = command.stderr.unwrap_or(Stdio::MakePipe);
169+
let stderr = command.stderr.take().unwrap_or(Stdio::MakePipe);
166170
let stderr = Command::create_pipe(stderr)?;
167171
if let Some(con) = stderr {
168172
cmd.stderr_init(con)
@@ -171,7 +175,7 @@ pub fn output(command: &mut Command) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>
171175
};
172176

173177
// Setup Stdin
174-
let stdin = command.stdin.unwrap_or(Stdio::Null);
178+
let stdin = command.stdin.take().unwrap_or(Stdio::Null);
175179
let stdin = Command::create_stdin(stdin)?;
176180
if let Some(con) = stdin {
177181
cmd.stdin_init(con)
@@ -217,25 +221,19 @@ impl From<ChildPipe> for Stdio {
217221

218222
impl From<io::Stdout> for Stdio {
219223
fn from(_: io::Stdout) -> Stdio {
220-
// FIXME: This is wrong.
221-
// Instead, the Stdio we have here should be a unit struct.
222-
panic!("unsupported")
224+
Stdio::Inherit
223225
}
224226
}
225227

226228
impl From<io::Stderr> for Stdio {
227229
fn from(_: io::Stderr) -> Stdio {
228-
// FIXME: This is wrong.
229-
// Instead, the Stdio we have here should be a unit struct.
230-
panic!("unsupported")
230+
Stdio::Inherit
231231
}
232232
}
233233

234234
impl From<File> for Stdio {
235-
fn from(_file: File) -> Stdio {
236-
// FIXME: This is wrong.
237-
// Instead, the Stdio we have here should be a unit struct.
238-
panic!("unsupported")
235+
fn from(file: File) -> Stdio {
236+
Stdio::InheritFile(file)
239237
}
240238
}
241239

0 commit comments

Comments
 (0)