Skip to content
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

CTRL-C event kills the application #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

cbucher
Copy link
Owner

@cbucher cbucher commented Jun 17, 2015

git-cmd.exe has a bad behavior when it receives CTRL-C event. A command line shell must handle the events.
For example, CTRL-C should be used to terminate the current command and not to terminate the shell himself.

When git-cmd.exe is launched, git-cmd.exe launches a child process (for example cmd.exe).
git-cmd.exe monitors the child process. When the child process exits, git-cmd.exe exits too.

When the user presses CTRL-C, the Windows console receives Windows messages for WM_KEYDOWN/WM_KEYUP.
Then the TranslateMessage function generates a CTRL-C event.

The CTRL-C event is handled by the Control Handler Function.
When a CTRL_BREAK_EVENT, CTRL_LOGOFF_EVENT, or CTRL_SHUTDOWN_EVENT signal is received, the control handler returns FALSE. Doing this causes the signal to be passed to the next control handler function. If no other control handlers have been registered or none of the registered handlers returns TRUE, the default handler will be used, resulting in the process being terminated.

cmd.exe Control Handler function terminates the current command and returns FALSE.
git-cmd.exe has no Control Handler Function registered. So git-cmd.exe is terminated.

When git-cmd.exe is used with programs like ConsoleZ, ConsoleZ injects a dll in git-cmd.exe and monitors this process.
When the user presses CTRL-C, git-cmd is terminated and so the ConsoleZ's tab is closed.

To fix this behavior, we can simply register a Control Handler function that returns TRUE (for all events). In this case the only way to exit this program is the launched command end.

Signed-off-by: Christophe Bucher Developer [email protected]

git-cmd.exe has a bad behavior when it receives CTRL-C event. A command line shell must handle the events.
For example, CTRL-C should be used to terminate the current command and not to terminate the shell himself.

When git-cmd.exe is launched, git-cmd.exe launches a child process (for example cmd.exe).
git-cmd.exe monitors the child process. When the child process exits, git-cmd.exe exits too.

When the user presses CTRL-C, the Windows console receives Windows messages for WM_KEYDOWN/WM_KEYUP.
Then the TranslateMessage function generates a CTRL-C event.

The CTRL-C event is handled by the Control Handler Function.
When a CTRL_BREAK_EVENT, CTRL_LOGOFF_EVENT, or CTRL_SHUTDOWN_EVENT signal is received, the control handler returns FALSE. Doing this causes the signal to be passed to the next control handler function. If no other control handlers have been registered or none of the registered handlers returns TRUE, the default handler will be used, resulting in the process being terminated.

cmd.exe Control Handler function terminates the current command and returns FALSE.
git-cmd.exe has no Control Handler Function registered. So git-cmd.exe is terminated.

When git-cmd.exe is used with programs like ConsoleZ, ConsoleZ injects a dll in git-cmd.exe and monitors this process.
When the user presses CTRL-C, git-cmd is terminated and so the ConsoleZ's tab is closed.

To fix this behavior, we can simply register a Control Handler function that returns TRUE (for all events). In this case the only way to exit this program is the launched command end.

Signed-off-by: Christophe Bucher Developer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant