-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add empty ctrlc handler on Windows. #6004
Conversation
When exec_replacing the cargo process, we want the new process to get any signals. This already works fine on Unix. On Windows, pressing ctrlc kills the cargo process and doesn't pass the signal on to the child process. By adding an empty handler, we allow the child process to handle the signal instead.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @matklad (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
I would still like to add a test for this, but it's unclear how I would do so. @alexcrichton suggested using GenerateConsoleCtrlEvent, but are there examples of tests right now that spawn an external But...uh...I think I need help figuring out how to set that up. :) |
@zachlute oh what I'm thinking is a test that does this:
I think that when Does that sounds possible? |
Yeah, that's pretty much what I was imagining, so good to hear confirmation I'm not ridiculous. I'll try to give it a go in the next couple of days. Thanks for the help! |
I'm beginning to believe writing a test for this is impossible. The basic issue is that
Things I have tried so far:
The fundamental issue is that there's no way to run even the special killer process as NOT under the same console as the test, so no matter what I do, the event kills the test. To do any of this at all required adding a way to spawn the runner process but not actually wait on it until we'd had a chance to run the second process, so that's in there, too. You can view this abomination here in case you have any brilliant ideas, but I am out of them: |
It's probably also worth noting that this broken test is horrifically slow, because it has to download and build the |
Oh dear, that really does make for a complicated function! I do think though that this'll be very valuable to have a test for! I'll take a crack at it tonight when I get back to a windows machine. |
Aha I'm now remembering something! Turns out on MSYS programs do not get a ctrl-c event. I think they're just killed with This means that ctrl-c handlers (via |
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.
Ok I tried my damnednest and couldn't get a test working. The docs for GenerateConsoleCtrlEvent
don't really make sense to me becuase I create a new process group and then had it send a signal to itself, but it still killed the main test.
In any case this is good enough to land I believe.
|
||
pub fn exec_replace(process_builder: &ProcessBuilder) -> CargoResult<()> { | ||
unsafe { | ||
if SetConsoleCtrlHandler(Some(ctrlc_handler), TRUE) == FALSE { |
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.
I think this could probably use None
to specify that the signal should be ignored, 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.
You would think that, wouldn't you? But it doesn't work. What happens is that it EATS the Ctrl+C and it doesn't make it to the child process, so it's actually worse than the status quo because then you can't kill the cargo process OR the child process without task-killing it.
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 ok, good to know!
@bors: r+ |
📌 Commit 6a3f4b9 has been approved by |
Add empty ctrlc handler on Windows. Fixes #6000. This is a 'better' version of PR #6002 that accomplishes the same thing using only `winapi` calls without the dependency on the `ctrlc` crate or spawning an additional thread. ---- When exec_replacing the cargo process, we want the new process to get any signals. This already works fine on Unix. On Windows, pressing ctrlc kills the cargo process and doesn't pass the signal on to the child process. By adding an empty handler, we allow the child process to handle the signal instead.
☀️ Test successful - status-appveyor, status-travis |
Attempt to replicate the functionality from <rust-lang/cargo#6004> in order to pass Ctrl+C on in Windows Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Attempt to replicate the functionality from <rust-lang/cargo#6004> in order to pass Ctrl+C on in Windows Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Attempt to replicate the functionality from <rust-lang/cargo#6004> in order to pass Ctrl+C on in Windows Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Fixes #6000.
This is a 'better' version of PR #6002 that accomplishes the same thing using only
winapi
calls without the dependency on thectrlc
crate or spawning an additional thread.When exec_replacing the cargo process, we want the new process to get any signals. This already works fine on Unix.
On Windows, pressing ctrlc kills the cargo process and doesn't pass the signal on to the child process. By adding an empty handler, we allow the child process to handle the signal instead.