Skip to content

Commit 3c07c0c

Browse files
committed
Support Ctrl+C in interactive session and fix Ctrl+Break handler
1 parent 69be768 commit 3c07c0c

File tree

3 files changed

+18
-64
lines changed

3 files changed

+18
-64
lines changed

contrib/win32/win32compat/shell-host.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* Author: Manoj Ampalam <[email protected]>
33
* Primitive shell-host to support parsing of cmd.exe input and async IO redirection
44
*
5+
* Author: Ray Heyes <[email protected]>
6+
* PTY with ANSI emulation wrapper
7+
*
58
* Copyright (c) 2015 Microsoft Corp.
69
* All rights reserved
710
*
@@ -807,7 +810,7 @@ DWORD WINAPI ProcessPipes(LPVOID p) {
807810
/* process data from pipe_in and route appropriately */
808811
while (1) {
809812
char buf[128];
810-
DWORD rd = 0, wr = 0, i = 0;
813+
DWORD rd = 0, wr = 0, i = -1;
811814

812815
GOTO_CLEANUP_ON_FALSE(ReadFile(pipe_in, buf, 128, &rd, NULL));
813816
if (!istty) { /* no tty, just send it accross */
@@ -817,10 +820,15 @@ DWORD WINAPI ProcessPipes(LPVOID p) {
817820

818821
bStartup = FALSE;
819822

820-
while (i < rd) {
823+
while (++i < rd) {
821824

822825
INPUT_RECORD ir;
823826

827+
if (buf[i] == 3) {/*Ctrl+C - Raise Ctrl+C*/
828+
GenerateConsoleCtrlEvent(CTRL_C_EVENT, childProcessId);
829+
continue;
830+
}
831+
824832
if (bAnsi) {
825833
ir.EventType = KEY_EVENT;
826834
ir.Event.KeyEvent.bKeyDown = TRUE;
@@ -950,7 +958,6 @@ DWORD WINAPI ProcessPipes(LPVOID p) {
950958
}
951959
}
952960

953-
i++;
954961
}
955962
}
956963

@@ -1115,7 +1122,9 @@ int wmain(int ac, wchar_t **av) {
11151122

11161123
/*TODO - pick this up from system32*/
11171124
cmd[0] = L'\0';
1118-
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_PATH, L"cmd.exe"));
1125+
if (ac)
1126+
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_PATH, L"cmd.exe"));
1127+
11191128
ac--;
11201129
av++;
11211130
if (ac)

contrib/win32/win32compat/signal.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ sw_raise(int sig) {
149149
case W32_SIGCHLD:
150150
sw_cleanup_child_zombies();
151151
break;
152-
default:
153-
ExitThread(1);
152+
default: /* exit process */
153+
exit(0);
154154
}
155155

156156
return 0;
157157
}
158158

159-
/* processes pending signals, return EINTR if any are processed*/
159+
/* processes pending signals, return -1 and errno=EINTR if any are processed*/
160160
static int
161161
sw_process_pending_signals() {
162162
sigset_t pending_tmp = pending_signals;
@@ -210,11 +210,11 @@ sw_process_pending_signals() {
210210
/*
211211
* Main wait routine used by all blocking calls.
212212
* It wakes up on
213-
* - any signals (errno = EINTR ) - TODO
213+
* - any signals (errno = EINTR )
214214
* - any of the supplied events set
215215
* - any APCs caused by IO completions
216216
* - time out
217-
* - Returns 0 on IO completion, timeout -1 on rest
217+
* - Returns 0 on IO completion and timeout, -1 on rest
218218
* if milli_seconds is 0, this function returns 0, its called with 0
219219
* to execute any scheduled APCs
220220
*/

ssh.c

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -244,50 +244,6 @@ tilde_expand_paths(char **paths, u_int num_paths)
244244
}
245245
}
246246

247-
#ifdef WIN32_FIXME
248-
249-
/*
250-
* This function handles exit signal.
251-
*/
252-
253-
BOOL WINAPI CtrlHandlerRoutine(DWORD dwCtrlType)
254-
{
255-
256-
switch( dwCtrlType )
257-
{
258-
// Handle the CTRL-C signal.
259-
case CTRL_C_EVENT:
260-
// send CTRL_C code to the remote app via sshd server
261-
//buffer_put_char(&stdin_buffer, 0x3); // control-c is decimal 3
262-
//Beep( 750, 300 );
263-
//return( TRUE ); // we have handled it. FALSE would be go to next handler
264-
265-
case CTRL_BREAK_EVENT:
266-
// send CTRL_BREAK to the remote side ?
267-
//return TRUE;
268-
269-
case CTRL_CLOSE_EVENT:
270-
case CTRL_LOGOFF_EVENT:
271-
case CTRL_SHUTDOWN_EVENT:
272-
// send SHELL_CODE_TERMINATE to the remote side
273-
//return FALSE ; // go to next handler
274-
275-
default:
276-
break;
277-
//return FALSE;
278-
}
279-
280-
debug("Exit signal received...");
281-
282-
cleanup_exit(0);
283-
284-
return TRUE;
285-
286-
}
287-
288-
#endif /* WIN32_FIXME */
289-
290-
291247
/*
292248
* Attempt to resolve a host name / port to a set of addresses and
293249
* optionally return any CNAMEs encountered along the way.
@@ -574,23 +530,12 @@ main(int ac, char **av)
574530

575531
#ifdef WIN32_FIXME
576532

577-
/*
578-
* Setup exit signal handler for receiving signal, when
579-
* parent server is stopped.
580-
*/
581-
582-
SetConsoleCtrlHandler(CtrlHandlerRoutine, TRUE);
583-
584533
/*
585534
* Initialize wrapped stdio.
586535
*/
587536

588537
w32posix_initialize();
589538

590-
/* allocate_standard_descriptor(STDIN_FILENO);
591-
allocate_standard_descriptor(STDOUT_FILENO);
592-
allocate_standard_descriptor(STDERR_FILENO);*/
593-
594539
#endif
595540

596541
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */

0 commit comments

Comments
 (0)