-
Notifications
You must be signed in to change notification settings - Fork 653
windows: Read the PATH env var of the child #1337
Conversation
Thanks Alex! I'll take a look. It will take a bit since I'm a bit flooded right now, but I'll get to it (if nobody does beforehand). |
@piscisaureus this is a bit over my head, can you help please? :-) |
No time today but I will try to find a spare hour or so. The affected code is here: Lines 878 to 899 in c11a598
In pseudocode it should look like:
|
@piscisaureus Thanks! I'll also go through it. |
Hi @alexcrichton, sorry for the delay on this. Unfortunately your patch no longer applies because Can you rebase and work on a patch that applies to current master? |
Sure! I've rebased and tested on my local mingw installation, so hopefully it's working! |
* If found, `*path` and `*path_len` will be the value of PATH and the lenth, | ||
* respectively, and 1 will be returned. If not found, then 0 will be returned. | ||
*/ | ||
static int find_path(WCHAR *env, WCHAR **path, DWORD *path_len) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this set path to NULL and path_len to 0 in case it doesn't find it instead? You can also make it return *path to make the if check nicer.
Nice, thanks! Left a few more coments, nothing big though, the approach seems fine :-) |
The unix and windows process implementations diverge in their behavior when dealing with subprocesses that are spawned with a relative path. With unix the *child's* PATH environment variable is read, whereas with windows the *parent's* environment variable is read. This commit brings the two implementation in line with respect to their behavior of reading PATH by having both read the *child's* PATH environment variable. This involves looking into the user-provided environment on windows and extracting the PATH variable specifically so it can be inspected later on.
Thanks for taking a look! I've updated the patch. |
@@ -1131,7 +1147,7 @@ int uv_spawn(uv_loop_t* loop, | |||
free(arguments); | |||
free(cwd); | |||
free(env); | |||
free(path); | |||
free(alloc_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? We set path to alloc_path, so we should be freeing that one, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alloc_path
is the variable storing the allocation, and path
is just a pointer to something which is the actual path value (may or may not be an allocation). If PATH
is found in env
then path
doesn't need to be free'd (it's in the middle of an allocation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right. LGTM then.
Left a couple more comments, we are almost there :-) |
@saghul, looks ok? |
@alexcrichton yeah, will merge now! 👍 |
I just ran the tests on my Windows 7 machine and |
Running the tests locally causes the |
How are you running your tests? I'm running
I printed the error and it's ENOENT, so I assume it comes from here: https://github.com/joyent/libuv/blob/master/src/win/process.c#L1018 |
Ah I may be running the tests incorrectly then. I'm using mingw and I don't know how to run the tests otherwise so it looks something like this:
Could you add a print to |
That's an unusual way to run tests :-) I just ran them on a MSYS2/MinGW environment (built it with autotools), and the failure is the same. cmd.exe gives the same error :-S I'll add some prints. |
Hum, here are the paths being searched:
Of course it fails, the path where the exe is located is |
Got it! The PATH wasn't actually properly found:
vs
We also need to skip the null byte at the end of each env entry. I'll amend your patch and merge. |
Oh whoops, thanks @saghul for tracking that down! |
Landed in c7e4b31, thanks Alex! PS: Nice PR number ;-) |
The unix and windows process implementations diverge in their behavior
when dealing with subprocesses that are spawned with a relative path.
With unix the child's PATH environment variable is read, whereas
with windows the parent's environment variable is read.
This commit brings the two implementation in line with respect to
their behavior of reading PATH by having both read the child's PATH
environment variable. This involves looking into the user-provided
environment on windows and extracting the PATH variable specifically
so it can be inspected later on.
I'll cc #122 here as well, although I ended up discovering that after
writing this. It appears that there's more to this than I originally
thought, but I figured I'd at least put this out there!