]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #11784 : eminence/rust/fix_run_tests, r=alexcrichton
authorbors <bors@rust-lang.org>
Fri, 31 Jan 2014 02:11:30 +0000 (18:11 -0800)
committerbors <bors@rust-lang.org>
Fri, 31 Jan 2014 02:11:30 +0000 (18:11 -0800)
This test is designed to ensure that running a non-existent executable
results in a correct error message (FileNotFound in this case of this
test).  However, if you try to run an executable that doesn't exist, and
that requires searching through the $PATH, and one of the $PATH components
is not readable, then a PermissionDenied error will be returned, instead
of FileNotFound.

Using an absolute path skips the $PATH search logic in exec, thus by-passing the logic in exec that would have returned a PermissionDenied

In the specific case of my machine, /usr/bin/games was part of $PATH, but my user account wasn't in the games group (thus being unable to read /usr/bin/games)

See the man pages for execv and execve for more details.

I've tested this on Linux and OSX, and I am fairly certain that there will be no problems on Windows

1  2 
src/libstd/run.rs

diff --combined src/libstd/run.rs
index 482477b2f0eb9ec27d488c427477f89807d5c6eb,d0ca6efd2472b62ade7afcdd9dfc57a41c615777..ef2374f6095dad86aa0795864ea8dd6ed91b4b18
@@@ -223,22 -223,22 +223,22 @@@ impl Process 
          let (p, ch) = SharedChan::new();
          let ch_clone = ch.clone();
  
 -        do spawn {
 +        spawn(proc() {
              let _guard = io::ignore_io_error();
              let mut error = error;
              match error {
                  Some(ref mut e) => ch.send((2, e.read_to_end())),
                  None => ch.send((2, ~[]))
              }
 -        }
 -        do spawn {
 +        });
 +        spawn(proc() {
              let _guard = io::ignore_io_error();
              let mut output = output;
              match output {
                  Some(ref mut e) => ch_clone.send((1, e.read_to_end())),
                  None => ch_clone.send((1, ~[]))
              }
 -        }
 +        });
  
          let status = self.finish();
  
@@@ -360,7 -360,7 +360,7 @@@ mod tests 
              trapped_io_error = true;
              assert_eq!(e.kind, FileNotFound);
          }).inside(|| -> Option<run::ProcessOutput> {
-             run::process_output("no-binary-by-this-name-should-exist", [])
+             run::process_output("/no-binary-by-this-name-should-exist", [])
          });
          assert!(trapped_io_error);
          assert!(opt_outp.is_none());
          os::close(pipe_out.out as int);
          os::close(pipe_err.out as int);
  
 -        do spawn {
 +        spawn(proc() {
              writeclose(pipe_in.out, "test");
 -        }
 +        });
          let actual = readclose(pipe_out.input);
          readclose(pipe_err.input);
          process.finish();