-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass on null handle values to child process #103459
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @thomcc I think this can be considered a bug fix (see also rust-lang/libs-team#137 (comment)) so this is ready for review. |
It's too bad we can't run Crater on Windows. I am in favor of this change or something like it as a bug fix but I should note that I feel we still have an uncovered API use-case in situations like #105203 so the underlying issue of wanting a clearer API saying something like "please make something new here" has not been resolved. Also I should note that previously we removed some code that also did this conversion: 7ddf41c I feel like we should have some kind of test here. |
Does this PR rely on some undocumented behaviour? Windows documentation doesn't seem to say what happens when you set GUI apps can have stdio handles. Inheriting them while still creating a new useless empty console window doesn't look like a sane default behaviour but it is what happens with or without this PR. |
That's kind of why I linked that commit... it documented what can happen when these values are |
That commit only removed a no-op. The code already turned nulls to
I'm uncertain if this is documented somewhere but in any case this PR does not actually rely on any particular behaviour. A null handle is an invalid handle value (unlike
A console process can be spawned detached if you do not want a console to actually be created. Even if a console is created while inheriting handles, it's not necessarily useless. It can still be read from a written to. But, as you say, this PR isn't changing that behaviour. |
Ah, documentation is in the GetStdHandle docs:
|
As per #105203, I've added another commit that avoids setting |
8a6b010
to
93b774a
Compare
Super sorry for the delay here (busy and didn't want to half-ass reviews). This looks good to me. @bors r+ |
No worries! I'm well aware people have lives outside of Rust and a week is not long to wait at all. 😊 |
☀️ Test successful - checks-actions |
Finished benchmarking commit (01fbc5a): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesThis benchmark run did not return any relevant results for this metric. |
Pass on null handle values to child process Fixes rust-lang#101645 In Windows, stdio handles are (semantically speaking) `Option<Handle>` where `Handle` is a non-zero value. When spawning a process with `Stdio::Inherit`, Rust currently turns zero values into `-1` values. This has the unfortunate effect of breaking console subprocesses (which typically need stdio) that are spawned from gui applications (that lack stdio by default) because the console process won't be assigned handles from the newly created console (as they usually would in that situation). Worse, `-1` is actually [a valid handle](https://doc.rust-lang.org/std/os/windows/io/struct.OwnedHandle.html) which means "the current process". So if a console process, for example, waits on stdin and it has a `-1` value then the process will end up waiting on itself. This PR fixes it by propagating the nulls instead of converting them to `-1`. While I think the current behaviour is a mistake, changing it (however justified) is an API change so I think this PR should at least have some input from t-libs-api. So choosing at random... r? `@joshtriplett`
Fixes #101645
In Windows, stdio handles are (semantically speaking)
Option<Handle>
whereHandle
is a non-zero value. When spawning a process withStdio::Inherit
, Rust currently turns zero values into-1
values. This has the unfortunate effect of breaking console subprocesses (which typically need stdio) that are spawned from gui applications (that lack stdio by default) because the console process won't be assigned handles from the newly created console (as they usually would in that situation). Worse,-1
is actually a valid handle which means "the current process". So if a console process, for example, waits on stdin and it has a-1
value then the process will end up waiting on itself.This PR fixes it by propagating the nulls instead of converting them to
-1
.While I think the current behaviour is a mistake, changing it (however justified) is an API change so I think this PR should at least have some input from t-libs-api. So choosing at random...
r? @joshtriplett