uefi: process: Final Touchups · model-checking/verify-rust-std@c6cb67c
@@ -35,8 +35,6 @@ pub struct StdioPipes {
3535pub stderr: Option<AnonPipe>,
3636}
373738-// FIXME: This should be a unit struct, so we can always construct it
39-// The value here should be never used, since we cannot spawn processes.
4038pub enum Stdio {
4139Inherit,
4240Null,
@@ -45,12 +43,7 @@ pub enum Stdio {
45434644impl Command {
4745pub fn new(program: &OsStr) -> Command {
48-Command {
49-prog: program.to_os_string(),
50-args: Vec::from([program.to_os_string()]),
51-stdout: None,
52-stderr: None,
53-}
46+Command { prog: program.to_os_string(), args: Vec::new(), stdout: None, stderr: None }
5447}
55485649pub fn arg(&mut self, arg: &OsStr) {
@@ -122,6 +115,7 @@ impl Command {
122115pub fn output(&mut self) -> io::Result<(ExitStatus, Vec<u8>, Vec<u8>)> {
123116let mut cmd = uefi_command_internal::Command::load_image(&self.prog)?;
124117118+/* Setup Stdout */
125119let stdout: Option<helpers::Protocol<uefi_command_internal::PipeProtocol>> =
126120match self.stdout.take() {
127121Some(s) => Self::create_pipe(s),
@@ -131,7 +125,12 @@ impl Command {
131125)
132126.map(Some),
133127}?;
128+match stdout {
129+Some(stdout) => cmd.stdout_init(stdout),
130+None => cmd.stdout_inherit(),
131+};
134132133+/* Setup Stderr */
135134let stderr: Option<helpers::Protocol<uefi_command_internal::PipeProtocol>> =
136135match self.stderr.take() {
137136Some(s) => Self::create_pipe(s),
@@ -141,21 +140,15 @@ impl Command {
141140)
142141.map(Some),
143142}?;
144-145-match stdout {
146-Some(stdout) => cmd.stdout_init(stdout),
147-None => cmd.stdout_inherit(),
148-};
149143match stderr {
150144Some(stderr) => cmd.stderr_init(stderr),
151145None => cmd.stderr_inherit(),
152146};
153147154-if self.args.len() > 1 {
155-let args = self.args.iter().fold(OsString::new(), |mut acc, arg| {
156-if !acc.is_empty() {
157- acc.push(" ");
158-}
148+/* No reason to set args if only program name is preset */
149+if !self.args.is_empty() {
150+let args = self.args.iter().fold(OsString::from(&self.prog), |mut acc, arg| {
151+ acc.push(" ");
159152 acc.push(arg);
160153 acc
161154});
@@ -202,7 +195,11 @@ impl From<File> for Stdio {
202195}
203196204197impl fmt::Debug for Command {
205-fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
198+fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
199+self.prog.fmt(f)?;
200+for arg in &self.args {
201+ arg.fmt(f)?;
202+}
206203Ok(())
207204}
208205}
@@ -303,9 +300,11 @@ pub struct CommandArgs<'a> {
303300304301impl<'a> Iterator for CommandArgs<'a> {
305302type Item = &'a OsStr;
303+306304fn next(&mut self) -> Option<&'a OsStr> {
307305self.iter.next().map(|x| x.as_ref())
308306}
307+309308fn size_hint(&self) -> (usize, Option<usize>) {
310309self.iter.size_hint()
311310}
@@ -315,6 +314,7 @@ impl<'a> ExactSizeIterator for CommandArgs<'a> {
315314fn len(&self) -> usize {
316315self.iter.len()
317316}
317+318318fn is_empty(&self) -> bool {
319319self.iter.is_empty()
320320}