Uh oh!
There was an error while loading. Please reload this page.
Fixes #55775 -- fixed regression in Command::exec's handling of PATH. - #55793
Fixes #55775 -- fixed regression in Command::exec's handling of PATH.#55793alex wants to merge 1 commit into
Conversation
alexcrichton
commented
Nov 9, 2018
Thanks for this! To confirm, it sounded like you took a look at glibc's source to start off with, is this what glibc actually does in terms of its exec method? |
alex
commented
Nov 9, 2018
Not really, it just calls Which, under the original code, would be the new env we just built. To be honest, I don't fully understand why this behavior occurs. |
alexcrichton
commented
Nov 9, 2018
Oh I think this is the operative line of code where if That's... really weird. Let's discuss this a bit more on the issue |
alex
commented
Nov 9, 2018
Ooof, you're right. I think I should change this patch to match that behavior. Do you agree? |
alexcrichton
commented
Nov 9, 2018
Ok yeah I think it's probably best to basically continue to match glibc in this regard, so let's have the fallback of a missing I think we perhaps later may want to seriously look into what it would take to change up |
fc185df to
1a1b53eComparealex
commented
Nov 9, 2018
Done. If nothing else we're getting some more tests for |
Uh oh!
There was an error while loading. Please reload this page.
alexcrichton
commented
Nov 9, 2018
Heh, indeed! |
1a1b53e to
893f539Comparealex
commented
Nov 12, 2018
This should be good to go. |
alexcrichton
commented
Nov 12, 2018
@bors: r+ |
bors
commented
Nov 12, 2018
📌 Commit 893f539 has been approved by |
…r=alexcrichton Fixesrust-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
kennytm
commented
Nov 13, 2018
@bors r- The new tests likely failed on |
alex
commented
Nov 13, 2018
Does android not have |
kennytm
commented
Nov 13, 2018
@alex iirc android doesn't have |
ollie27
commented
Nov 13, 2018
It has |
alex
commented
Nov 13, 2018
Ooof, thanks. |
893f539 to
cda8d6aComparealex
commented
Nov 13, 2018
Added an Android specific fallback path. |
rust-highfive
commented
Nov 13, 2018
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
ollie27
commented
Nov 13, 2018
musl uses a different set of paths again: https://git.musl-libc.org/cgit/musl/tree/src/process/execvp.c#n21 Every libc seems to differ so If we're going to hardcode these paths we'll have to check every libc. |
cda8d6a to
a17d79eCompare… of PATH.
This restores the previous behavior where if env_clear() or env_remove("PATH") was used we fall back to a default PATH of "/bin:/usr/bin"a17d79e to
7226f41Comparealex
commented
Nov 13, 2018
Are there other libc's I ought to check? (It's worth noting that for some of these, the fallback-path varies based on compilation options. I selected the one I understand to be the standard choice.) |
alexcrichton
commented
Nov 13, 2018
Before we go too much further down this path, perhaps we should take a step back and see if this is the right approach? The original PR was fixing #46775 which is largely just working with It seems to me like a simpler solution for #55775 (the regression here) is to revert #55359 and simply access @alex does that fix sound right to you? |
alex
commented
Nov 13, 2018
I don't agree with this analysis. a) I don't believe there's any cases where we're reading from the global env without a lock. In this patch we access the temporary env directly, which is fine because we own it, and we access the process env via the public std APIs, which are safe. b) Adding a lock would not fix the issue I described in #46775 where we have a global reference that escapes the lifetime of the value it points at. It's possible there's a different approach than the one I took that'd work, but I don't believe additional locking is necessary or sufficient. |
alexcrichton
commented
Nov 13, 2018
Hm isn't this line reading the environment without a lock? (at least in some situations) For adding a lock, I'm thinking the code looks like this: let _guard = acquire_env_lock();let old_env = *sys::os::environ();*sys::os::environ() = new_env;let _reset_on_drop = on_drop(|| {*sys::os::environ() = old_env;});// do the execWe only temporarily change the entire environment for the block, but outside the block no other thread will see a visible change |
alex
commented
Nov 13, 2018
Hmm, accessing Your actual proposal isn't about the locking (though it's necessary for safety), it's about changing the code back to mutating the env, so we can just let libc do it's thing, and ensuring we restore the pointer if we fail. Is that right? |
alexcrichton
commented
Nov 13, 2018
Heh sure yeah! That's a good way to put it too. Basically we take the original code and update it to restore the old env on failure. That would fix your test cases I believe (because the env doesn't change across calls to Aftewards we'd then fix the orthogonal issue of "what if other threads are running around during |
alex
commented
Nov 13, 2018
Yes, I think that'd work. I won't have time to work on it for another few days (probably the weekend). If anyone else is rearing to work on this, you're welcome to steal it, otherwise I"ll get to this then. |
This restores the previous behavior where if env_clear() or env_remove() was used, the parent's PATH would be consulted.
r? @alexcrichton