Support Ctrl+C in interactive session and fix Ctrl+Break handler

This commit is contained in:
Manoj Ampalam 2016-09-27 11:57:43 -07:00
parent 69be768f2e
commit 3c07c0c9ae
3 changed files with 18 additions and 64 deletions

View File

@ -2,6 +2,9 @@
* Author: Manoj Ampalam <manoj.ampalam@microsoft.com>
* Primitive shell-host to support parsing of cmd.exe input and async IO redirection
*
* Author: Ray Heyes <ray.hayes@microsoft.com>
* PTY with ANSI emulation wrapper
*
* Copyright (c) 2015 Microsoft Corp.
* All rights reserved
*
@ -807,7 +810,7 @@ DWORD WINAPI ProcessPipes(LPVOID p) {
/* process data from pipe_in and route appropriately */
while (1) {
char buf[128];
DWORD rd = 0, wr = 0, i = 0;
DWORD rd = 0, wr = 0, i = -1;
GOTO_CLEANUP_ON_FALSE(ReadFile(pipe_in, buf, 128, &rd, NULL));
if (!istty) { /* no tty, just send it accross */
@ -817,10 +820,15 @@ DWORD WINAPI ProcessPipes(LPVOID p) {
bStartup = FALSE;
while (i < rd) {
while (++i < rd) {
INPUT_RECORD ir;
if (buf[i] == 3) {/*Ctrl+C - Raise Ctrl+C*/
GenerateConsoleCtrlEvent(CTRL_C_EVENT, childProcessId);
continue;
}
if (bAnsi) {
ir.EventType = KEY_EVENT;
ir.Event.KeyEvent.bKeyDown = TRUE;
@ -950,7 +958,6 @@ DWORD WINAPI ProcessPipes(LPVOID p) {
}
}
i++;
}
}
@ -1115,7 +1122,9 @@ int wmain(int ac, wchar_t **av) {
/*TODO - pick this up from system32*/
cmd[0] = L'\0';
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_PATH, L"cmd.exe"));
if (ac)
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_PATH, L"cmd.exe"));
ac--;
av++;
if (ac)

View File

@ -149,14 +149,14 @@ sw_raise(int sig) {
case W32_SIGCHLD:
sw_cleanup_child_zombies();
break;
default:
ExitThread(1);
default: /* exit process */
exit(0);
}
return 0;
}
/* processes pending signals, return EINTR if any are processed*/
/* processes pending signals, return -1 and errno=EINTR if any are processed*/
static int
sw_process_pending_signals() {
sigset_t pending_tmp = pending_signals;
@ -210,11 +210,11 @@ sw_process_pending_signals() {
/*
* Main wait routine used by all blocking calls.
* It wakes up on
* - any signals (errno = EINTR ) - TODO
* - any signals (errno = EINTR )
* - any of the supplied events set
* - any APCs caused by IO completions
* - time out
* - Returns 0 on IO completion, timeout -1 on rest
* - Returns 0 on IO completion and timeout, -1 on rest
* if milli_seconds is 0, this function returns 0, its called with 0
* to execute any scheduled APCs
*/

55
ssh.c
View File

@ -244,50 +244,6 @@ tilde_expand_paths(char **paths, u_int num_paths)
}
}
#ifdef WIN32_FIXME
/*
* This function handles exit signal.
*/
BOOL WINAPI CtrlHandlerRoutine(DWORD dwCtrlType)
{
switch( dwCtrlType )
{
// Handle the CTRL-C signal.
case CTRL_C_EVENT:
// send CTRL_C code to the remote app via sshd server
//buffer_put_char(&stdin_buffer, 0x3); // control-c is decimal 3
//Beep( 750, 300 );
//return( TRUE ); // we have handled it. FALSE would be go to next handler
case CTRL_BREAK_EVENT:
// send CTRL_BREAK to the remote side ?
//return TRUE;
case CTRL_CLOSE_EVENT:
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
// send SHELL_CODE_TERMINATE to the remote side
//return FALSE ; // go to next handler
default:
break;
//return FALSE;
}
debug("Exit signal received...");
cleanup_exit(0);
return TRUE;
}
#endif /* WIN32_FIXME */
/*
* Attempt to resolve a host name / port to a set of addresses and
* optionally return any CNAMEs encountered along the way.
@ -574,23 +530,12 @@ main(int ac, char **av)
#ifdef WIN32_FIXME
/*
* Setup exit signal handler for receiving signal, when
* parent server is stopped.
*/
SetConsoleCtrlHandler(CtrlHandlerRoutine, TRUE);
/*
* Initialize wrapped stdio.
*/
w32posix_initialize();
/* allocate_standard_descriptor(STDIN_FILENO);
allocate_standard_descriptor(STDOUT_FILENO);
allocate_standard_descriptor(STDERR_FILENO);*/
#endif
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */