-
Notifications
You must be signed in to change notification settings - Fork 13.3k
std: Fix inheriting standard handles on windows #24873
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
Conversation
r? @pcwalton (rust_highfive has picked a reviewer for you, use r? to override) |
fda3347
to
9761b00
Compare
r? @aturon Also nominating for beta cherry-pick. |
|
||
let mut pi = zeroed_process_information(); | ||
let mut create_err = None; | ||
let stdio_handle = |io: &Stdio, id: libc::DWORD| { |
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 this be an inner function rather than a closure?
by the way, what are the implications of using a closure (which doesn't close over anything) over an inner function?
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.
Oh wow I guess this doesn't close over anything any more (it did previously). If you're not closing over anything then I'd recommend a free function personally as you probably need to have type annotations anyway.
7694ee7
to
1d8388e
Compare
create_err = Some(Error::last_os_error()); | ||
} | ||
}) | ||
let (envp, _data) = make_envp(cfg.env.as_ref()); |
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.
why return _data
here?
1d8388e
to
cb41b82
Compare
Oy, fun bug :) This PR LGTM. Cute use of "RAII". |
@tamird The reason to return |
@aturon cool, that's what I suspected, thanks. Allocating an empty vector in the |
It's possible that it could just return a |
⌛ Testing commit cb41b82 with merge f20b8e8... |
💔 Test failed - auto-win-32-opt |
@bors: retry On Tue, Apr 28, 2015 at 1:43 AM, bors notifications@github.com wrote:
|
⌛ Testing commit cb41b82 with merge 99f628b... |
💔 Test failed - auto-win-64-nopt-t |
Currently if a standard I/O handle is set to inherited on Windows, no action is taken and the slot in the process information description is set to `INVALID_HANDLE_VALUE`. Due to our passing of `STARTF_USESTDHANDLES`, however, this means that the handle is actually set to nothing and if a child tries to print it will generate an error. This commit fixes this behavior by explicitly creating stdio handles to be placed in these slots by duplicating the current process's I/O handles. This is presumably what previously happened silently by using a file-descriptor-based implementation instead of a `HANDLE`-centric implementation. Along the way this cleans up a lot of code in `Process::spawn` for Windows by ensuring destructors are always run, using more RAII, and limiting the scope of `unsafe` wherever possible.
cb41b82
to
c1149ed
Compare
Conflicts: src/libstd/sys/windows/fs2.rs
triage: beta-accepted (as a special case for the 1.0 release; post 1.0 changes like this probably would not be accepted for backport) |
Backported. |
Currently if a standard I/O handle is set to inherited on Windows, no action is
taken and the slot in the process information description is set to
INVALID_HANDLE_VALUE
. Due to our passing ofSTARTF_USESTDHANDLES
, however,this means that the handle is actually set to nothing and if a child tries to
print it will generate an error.
This commit fixes this behavior by explicitly creating stdio handles to be
placed in these slots by duplicating the current process's I/O handles. This is
presumably what previously happened silently by using a file-descriptor-based
implementation instead of a
HANDLE
-centric implementation.Along the way this cleans up a lot of code in
Process::spawn
for Windows byensuring destructors are always run, using more RAII, and limiting the scope of
unsafe
wherever possible.