Skip to content

Commit

Permalink
Rollup merge of rust-lang#55793 - alex:command-exec-path-regression, …
Browse files Browse the repository at this point in the history
…r=alexcrichton

Fixes rust-lang#55775 -- fixed regression in Command::exec's handling of PATH.

This restores the previous behavior where if env_clear() or env_remove() was used, the parent's PATH would be consulted.

r? @alexcrichton
  • Loading branch information
pietroalbini authored Nov 12, 2018
2 parents ffa7767 + 893f539 commit e9376b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/libstd/sys/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,15 @@ impl Command {
Some(envp) => {
match envp.get_items().iter().find(|var| var.as_bytes().starts_with(b"PATH=")) {
Some(p) => &p.as_bytes()[5..],
None => return None,
// Chosen to match what glibc does if there's no PATH variable
None => b"/bin:/usr/bin",
}
},
// maybe_envp is None if the process isn't changing the parent's env at all.
None => {
match parent_path.as_ref() {
Some(p) => p.as_bytes(),
None => return None,
None => b"/bin:/usr/bin",
}
},
};
Expand Down
20 changes: 20 additions & 0 deletions src/test/run-pass/command-exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ fn main() {
println!("passed");
}

"exec-test6" => {
let err = Command::new("echo").arg("passed").env_clear().exec();
panic!("failed to spawn: {}", err);
}

"exec-test7" => {
let err = Command::new("echo").arg("passed").env_remove("PATH").exec();
panic!("failed to spawn: {}", err);
}

_ => panic!("unknown argument: {}", arg),
}
return
Expand Down Expand Up @@ -84,4 +94,14 @@ fn main() {
assert!(output.status.success());
assert!(output.stderr.is_empty());
assert_eq!(output.stdout, b"passed\n");

let output = Command::new(&me).arg("exec-test6").output().unwrap();
assert!(output.status.success());
assert!(output.stderr.is_empty());
assert_eq!(output.stdout, b"passed\n");

let output = Command::new(&me).arg("exec-test7").output().unwrap();
assert!(output.status.success());
assert!(output.stderr.is_empty());
assert_eq!(output.stdout, b"passed\n");
}

0 comments on commit e9376b7

Please sign in to comment.