forked from Alexpux/Cygwin
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exit_process.h: fix handling of SIGINT and SIGTERM
Handle SIGINT and SIGTERM by injecting into the process a thread that runs ExitProcess. Use TerminateProcess otherwise. In both cases, enumerate the entire process tree. This fixes git-for-windows/git#1219 Signed-off-by: Adam Smith <afsmith92@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
- Loading branch information
Showing
1 changed file
with
56 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53e5c03
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.
@dscho Unfortunately after further investigation it seems the change I added doesn't fix the node ctrl+c issue.
All of the child processes are killed, but processes still can't respond to
SIGINT
orSIGKILL
. It seems that line 179 always evaluates to false, andTerminateProcess
is always used. It looks like after this lineexit_code === SIGINT
andexit_code === SIGTERM
always evaluates to false. If I force the use ofterminate_process_with_remote_thread
. The node child processes don't get closed and this cleanup code doesn't run either:I'm continuing to investigate. I'll see if I can make a change to
terminate_process_with_remote_thread
that resolves the issue.53e5c03
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.
The
kill
utility should not be involved at all, so that line 179 should not be hit at all...53e5c03
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.
Where is
exit_process
called when responding to ctrl+c? If it's passing the exit code in the same way e.g.sig + 128
then theexit_code == SIGINT
check will fail.53e5c03
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.
It's called via
signal()
inexceptions.cc
. AFAICT you callexit_process()
correctly there...53e5c03
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 no. I was mistaken!
msys2-runtime/winsup/cygwin/exceptions.cc
Line 1564 in 53e5c03
53e5c03
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.
Maybe we should pass the real code instead, and let
exit_process()
decide whether to add 128 or not?53e5c03
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 made up my mind and think that testing
exit_code & 0x7f
might be better. My proposed fix: dscho@fix-ctrl-c-againWhat do you think?
53e5c03
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 tested this with Node v6.10.2 as shipped in MSYS2 and with this script:
This is the "screenshot":
So I call this success and will push my fix ;-)
53e5c03
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.
Actually... After testing a bit further, it looks like the new code path is not hit in that case, and I cannot get it to work with
kill.exe
. Will keep digging, even if I do not really have any time to spend on this ;-)53e5c03
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.
@dscho I'm continuing to investigate as well. Would it be best to revert the patch at this point?
That sounds reasonable to me.
53e5c03
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.
Also, I found a different implementation of the safe ExitProcess in this thread -- I've been messing with this.
53e5c03
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.
After chasing down this rabbit hole, I finally have something that really seems to work: dscho@fix-ctrl-c-again
@afsmith92 would you mind testing this? It also requires
kill.exe
to be rebuilt (cd ../utils && make kill.exe
after you builtmsys0.dll
), as it has to spawnkill.exe
process so that that one can attach to the Console of the target process and send the Ctrl event.53e5c03
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.
Absolutely. I'll have it tested within the next half hour.
53e5c03
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.
Still compiling..
53e5c03
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.
Works perfectly. Tested in a PortableGit with
node v6.11.2
. Killed all child processes and was able to handleSIGINT
:logged
responding to SIGINT
to the console after ctrl +cThank you so much for taking the time to figure this out, and I'm sorry for getting you dragged into this issue. I was only following the issue on git-for-windows -- not the issue logged to node -- and I wasn't aware of the issues with
SIGINT
andSIGTERM
handling (until you tagged me in the node issue) and thus only tested for the child processes issue described in the git-for-windows issue.I'll keep an eye on the issues list for this repo, and I'll jump in if I see anything I think I can help with in the future.
53e5c03
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.
No worries! You helped. That means a lot to me. And thanks for verifying my latest attempt at a fix!