Skip to content

Commit 46a6cc9

Browse files
author
manojampalam
committed
Fixes to hang on TTY child process exit
1 parent 08cda06 commit 46a6cc9

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

contrib/win32/win32compat/shell-host.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,9 +1116,13 @@ int start_with_pty(int ac, wchar_t **av) {
11161116
childProcessId = pi.dwProcessId;
11171117

11181118
FreeConsole();
1119+
Sleep(20);
11191120
while (!AttachConsole(pi.dwProcessId))
11201121
{
1121-
Sleep(1000);
1122+
DWORD exit_code;
1123+
if (GetExitCodeProcess(pi.hProcess, &exit_code) && exit_code != STILL_ACTIVE)
1124+
break;
1125+
Sleep(100);
11221126
}
11231127

11241128
/* monitor child exist */

session.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ int do_exec_windows(Session *s, const char *command, int pty) {
567567
free(tmp);
568568

569569
if (s->display)
570-
SetEnvironmentVariableW(L"DISPLAY", s->display);
570+
SetEnvironmentVariableA("DISPLAY", s->display);
571571

572572

573573
//_wchdir(pw_dir_w);
@@ -674,8 +674,12 @@ int do_exec_windows(Session *s, const char *command, int pty) {
674674
FreeConsole();
675675
if (!debug_flag)
676676
ImpersonateLoggedOnUser(hToken);
677+
Sleep(20);
677678
while (AttachConsole(pi.dwProcessId) == FALSE) {
678-
Sleep(200);
679+
DWORD exit_code;
680+
if (GetExitCodeProcess(pi.hProcess, &exit_code) && exit_code != STILL_ACTIVE)
681+
break;
682+
Sleep(100);
679683
}
680684
if (!debug_flag)
681685
RevertToSelf();

0 commit comments

Comments
 (0)