diff options
| author | Bryan Drewery <bryan@shatow.net> | 2018-03-19 15:40:09 -0700 |
|---|---|---|
| committer | Bryan Drewery <bryan@shatow.net> | 2018-03-19 15:40:09 -0700 |
| commit | 6212904dd800864ca20ede8690fc827a1169fa26 (patch) | |
| tree | 81e4910d6abcf523fc599fcc3c926c4813d9c11d /src/libstd/sys_common | |
| parent | 00dac20e017d321b9999b04fd6d3132c4a21a388 (diff) | |
Don't use posix_spawn() if PATH was modified in the environment.
The expected behavior is that the environment's PATH should be used to find the process. posix_spawn() could be used if we iterated PATH to search for the binary to execute. For now just skip posix_spawn() if PATH is modified.
Diffstat (limited to 'src/libstd/sys_common')
| -rw-r--r-- | src/libstd/sys_common/process.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libstd/sys_common/process.rs b/src/libstd/sys_common/process.rs index fd1a5fdb410..775491d762c 100644 --- a/src/libstd/sys_common/process.rs +++ b/src/libstd/sys_common/process.rs @@ -47,6 +47,7 @@ impl EnvKey for DefaultEnvKey {} #[derive(Clone, Debug)] pub struct CommandEnv<K> { clear: bool, + saw_path: bool, vars: BTreeMap<K, Option<OsString>> } @@ -54,6 +55,7 @@ impl<K: EnvKey> Default for CommandEnv<K> { fn default() -> Self { CommandEnv { clear: false, + saw_path: false, vars: Default::default() } } @@ -108,9 +110,11 @@ impl<K: EnvKey> CommandEnv<K> { // The following functions build up changes pub fn set(&mut self, key: &OsStr, value: &OsStr) { + self.maybe_saw_path(&key); self.vars.insert(key.to_owned().into(), Some(value.to_owned())); } pub fn remove(&mut self, key: &OsStr) { + self.maybe_saw_path(&key); if self.clear { self.vars.remove(key); } else { @@ -121,4 +125,12 @@ impl<K: EnvKey> CommandEnv<K> { self.clear = true; self.vars.clear(); } + pub fn have_changed_path(&self) -> bool { + self.saw_path || self.clear + } + fn maybe_saw_path(&mut self, key: &OsStr) { + if !self.saw_path && key.to_os_string() == OsString::from("PATH") { + self.saw_path = true; + } + } } |
