mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-21 13:04:57 +02:00
Support Ctrl+C in interactive session and fix Ctrl+Break handler
This commit is contained in:
parent
69be768f2e
commit
3c07c0c9ae
@ -2,6 +2,9 @@
|
|||||||
* Author: Manoj Ampalam <manoj.ampalam@microsoft.com>
|
* Author: Manoj Ampalam <manoj.ampalam@microsoft.com>
|
||||||
* Primitive shell-host to support parsing of cmd.exe input and async IO redirection
|
* 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.
|
* Copyright (c) 2015 Microsoft Corp.
|
||||||
* All rights reserved
|
* All rights reserved
|
||||||
*
|
*
|
||||||
@ -807,7 +810,7 @@ DWORD WINAPI ProcessPipes(LPVOID p) {
|
|||||||
/* process data from pipe_in and route appropriately */
|
/* process data from pipe_in and route appropriately */
|
||||||
while (1) {
|
while (1) {
|
||||||
char buf[128];
|
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));
|
GOTO_CLEANUP_ON_FALSE(ReadFile(pipe_in, buf, 128, &rd, NULL));
|
||||||
if (!istty) { /* no tty, just send it accross */
|
if (!istty) { /* no tty, just send it accross */
|
||||||
@ -817,10 +820,15 @@ DWORD WINAPI ProcessPipes(LPVOID p) {
|
|||||||
|
|
||||||
bStartup = FALSE;
|
bStartup = FALSE;
|
||||||
|
|
||||||
while (i < rd) {
|
while (++i < rd) {
|
||||||
|
|
||||||
INPUT_RECORD ir;
|
INPUT_RECORD ir;
|
||||||
|
|
||||||
|
if (buf[i] == 3) {/*Ctrl+C - Raise Ctrl+C*/
|
||||||
|
GenerateConsoleCtrlEvent(CTRL_C_EVENT, childProcessId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (bAnsi) {
|
if (bAnsi) {
|
||||||
ir.EventType = KEY_EVENT;
|
ir.EventType = KEY_EVENT;
|
||||||
ir.Event.KeyEvent.bKeyDown = TRUE;
|
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*/
|
/*TODO - pick this up from system32*/
|
||||||
cmd[0] = L'\0';
|
cmd[0] = L'\0';
|
||||||
|
if (ac)
|
||||||
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_PATH, L"cmd.exe"));
|
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_PATH, L"cmd.exe"));
|
||||||
|
|
||||||
ac--;
|
ac--;
|
||||||
av++;
|
av++;
|
||||||
if (ac)
|
if (ac)
|
||||||
|
@ -149,14 +149,14 @@ sw_raise(int sig) {
|
|||||||
case W32_SIGCHLD:
|
case W32_SIGCHLD:
|
||||||
sw_cleanup_child_zombies();
|
sw_cleanup_child_zombies();
|
||||||
break;
|
break;
|
||||||
default:
|
default: /* exit process */
|
||||||
ExitThread(1);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 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
|
static int
|
||||||
sw_process_pending_signals() {
|
sw_process_pending_signals() {
|
||||||
sigset_t pending_tmp = pending_signals;
|
sigset_t pending_tmp = pending_signals;
|
||||||
@ -210,11 +210,11 @@ sw_process_pending_signals() {
|
|||||||
/*
|
/*
|
||||||
* Main wait routine used by all blocking calls.
|
* Main wait routine used by all blocking calls.
|
||||||
* It wakes up on
|
* It wakes up on
|
||||||
* - any signals (errno = EINTR ) - TODO
|
* - any signals (errno = EINTR )
|
||||||
* - any of the supplied events set
|
* - any of the supplied events set
|
||||||
* - any APCs caused by IO completions
|
* - any APCs caused by IO completions
|
||||||
* - time out
|
* - 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
|
* if milli_seconds is 0, this function returns 0, its called with 0
|
||||||
* to execute any scheduled APCs
|
* to execute any scheduled APCs
|
||||||
*/
|
*/
|
||||||
|
55
ssh.c
55
ssh.c
@ -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
|
* Attempt to resolve a host name / port to a set of addresses and
|
||||||
* optionally return any CNAMEs encountered along the way.
|
* optionally return any CNAMEs encountered along the way.
|
||||||
@ -574,23 +530,12 @@ main(int ac, char **av)
|
|||||||
|
|
||||||
#ifdef WIN32_FIXME
|
#ifdef WIN32_FIXME
|
||||||
|
|
||||||
/*
|
|
||||||
* Setup exit signal handler for receiving signal, when
|
|
||||||
* parent server is stopped.
|
|
||||||
*/
|
|
||||||
|
|
||||||
SetConsoleCtrlHandler(CtrlHandlerRoutine, TRUE);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize wrapped stdio.
|
* Initialize wrapped stdio.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
w32posix_initialize();
|
w32posix_initialize();
|
||||||
|
|
||||||
/* allocate_standard_descriptor(STDIN_FILENO);
|
|
||||||
allocate_standard_descriptor(STDOUT_FILENO);
|
|
||||||
allocate_standard_descriptor(STDERR_FILENO);*/
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
|
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user