#include "tls_pbuf.h"
#include "registry.h"
-#define ALWAYS_USE_PCON false
-#define USE_API_HOOK true
-
#ifndef PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE
#define PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE 0x00020016
#endif /* PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE */
static bool do_not_reset_switch_to_pcon;
static bool freeconsole_on_close = true;
-#if USE_API_HOOK
static void
set_switch_to_pcon (void)
{
set_ishybrid_and_switch_to_pcon (h);
return CreateProcessW_Orig (n, c, pa, ta, inh, f, e, d, si, pi);
}
-#else /* USE_API_HOOK */
-#define WriteFile_Orig 0
-#define ReadFile_Orig 0
-#define PeekConsoleInputA_Orig 0
-void set_ishybrid_and_switch_to_pcon (HANDLE) {}
-#endif /* USE_API_HOOK */
static char *
convert_mb_str (UINT cp_to, size_t *len_to,
{
if (fd < 0)
fd = fd_set;
- if (!isHybrid)
- {
- reset_switch_to_pcon ();
- return;
- }
if (fd == 0 && !get_ttyp ()->switch_to_pcon_in)
{
pid_restore = 0;
!pinfo (get_ttyp ()->pcon_pid))
get_ttyp ()->pcon_pid = myself->pid;
get_ttyp ()->switch_to_pcon_in = true;
+ if (isHybrid && !get_ttyp ()->switch_to_pcon_out)
+ {
+ wait_pcon_fwd ();
+ get_ttyp ()->switch_to_pcon_out = true;
+ }
}
else if ((fd == 1 || fd == 2) && !get_ttyp ()->switch_to_pcon_out)
{
!pinfo (get_ttyp ()->pcon_pid))
get_ttyp ()->pcon_pid = myself->pid;
get_ttyp ()->switch_to_pcon_out = true;
+ if (isHybrid)
+ get_ttyp ()->switch_to_pcon_in = true;
}
}
void
fhandler_pty_slave::reset_switch_to_pcon (void)
{
- if (isHybrid)
- this->set_switch_to_pcon (fd);
if (get_ttyp ()->pcon_pid &&
get_ttyp ()->pcon_pid != myself->pid &&
!!pinfo (get_ttyp ()->pcon_pid))
return;
if (isHybrid)
{
- if (ALWAYS_USE_PCON)
- {
- DWORD mode;
- GetConsoleMode (get_handle (), &mode);
- mode |= ENABLE_ECHO_INPUT;
- mode |= ENABLE_LINE_INPUT;
- mode &= ~ENABLE_PROCESSED_INPUT;
- SetConsoleMode (get_handle (), mode);
- }
- get_ttyp ()->pcon_pid = 0;
+ DWORD bytes_in_pipe;
+ WaitForSingleObject (input_mutex, INFINITE);
+ if (bytes_available (bytes_in_pipe) && !bytes_in_pipe)
+ ResetEvent (input_available_event);
+ FlushConsoleInputBuffer (get_handle ());
+ ReleaseMutex (input_mutex);
init_console_handler (true);
return;
}
if (do_not_reset_switch_to_pcon)
return;
- if (get_ttyp ()->switch_to_pcon_in)
- {
- DWORD mode;
- GetConsoleMode (get_handle (), &mode);
- SetConsoleMode (get_handle (), mode & ~ENABLE_ECHO_INPUT);
- }
if (get_ttyp ()->switch_to_pcon_out)
/* Wait for pty_master_fwd_thread() */
wait_pcon_fwd ();
fhandler_pty_common::to_be_read_from_pcon (void)
{
return get_ttyp ()->switch_to_pcon_in &&
- (!get_ttyp ()->mask_switch_to_pcon_in || ALWAYS_USE_PCON);
+ !get_ttyp ()->mask_switch_to_pcon_in;
}
void __reg3
if (ptr) /* Indicating not tcflush(). */
{
- reset_switch_to_pcon ();
mask_switch_to_pcon_in (true);
+ reset_switch_to_pcon ();
}
if (is_nonblocking () || !ptr) /* Indicating tcflush(). */
flags &= ~ENABLE_ECHO_INPUT;
if ((get_ttyp ()->ti.c_lflag & ISIG) &&
!(get_ttyp ()->ti.c_iflag & IGNBRK))
- flags |= ALWAYS_USE_PCON ? 0 : ENABLE_PROCESSED_INPUT;
+ flags |= ENABLE_PROCESSED_INPUT;
if (dwMode != flags)
SetConsoleMode (get_handle (), flags);
/* Read get_handle() instad of get_handle_cyg() */
char *buf = convert_mb_str
(CP_UTF8, &nlen, get_ttyp ()->term_code_page, (const char *) ptr, len);
+ WaitForSingleObject (input_mutex, INFINITE);
+
DWORD wLen;
WriteFile (to_slave, buf, nlen, &wLen, NULL);
- if (ALWAYS_USE_PCON &&
- (ti.c_lflag & ISIG) && memchr (p, ti.c_cc[VINTR], len))
- get_ttyp ()->kill_pgrp (SIGINT);
-
if (ti.c_lflag & ICANON)
{
if (memchr (buf, '\r', nlen))
else
SetEvent (input_available_event);
+ ReleaseMutex (input_mutex);
+
mb_str_free (buf);
return len;
}
- if (get_ttyp ()->switch_to_pcon_in &&
- (ti.c_lflag & ISIG) &&
- memchr (p, ti.c_cc[VINTR], len) &&
- get_ttyp ()->getpgid () == get_ttyp ()->pcon_pid)
- {
- DWORD n;
- /* Send ^C to pseudo console as well */
- WriteFile (to_slave, "\003", 1, &n, 0);
- }
-
line_edit_status status = line_edit (p, len, ti, &ret);
if (status > line_edit_signalled && status != line_edit_pipe_full)
ret = -1;
/* Clear screen to synchronize pseudo console screen buffer
with real terminal. This is necessary because pseudo
console screen buffer is empty at start. */
- if (get_ttyp ()->num_pcon_attached_slaves == 0
- && !ALWAYS_USE_PCON)
+ if (get_ttyp ()->num_pcon_attached_slaves == 0)
/* Assume this is the first process using this pty slave. */
get_ttyp ()->need_redraw_screen = true;
get_ttyp ()->num_pcon_attached_slaves ++;
}
- if (ALWAYS_USE_PCON && !isHybrid && pcon_attached_to == get_minor ())
- set_ishybrid_and_switch_to_pcon (get_output_handle ());
-
if (pcon_attached_to == get_minor () && native_maybe)
{
if (fd == 0)
/* Native windows program does not reset event on read.
Therefore, reset here if no input is available. */
DWORD bytes_in_pipe;
- if (bytes_available (bytes_in_pipe) && !bytes_in_pipe)
+ if (!to_be_read_from_pcon () &&
+ bytes_available (bytes_in_pipe) && !bytes_in_pipe)
ResetEvent (input_available_event);
reset_switch_to_pcon ();
if (get_ttyp ()->term_code_page == 0)
setup_locale ();
-#if USE_API_HOOK
/* Hook Console API */
if (get_pseudo_console ())
{
DO_HOOK (NULL, CreateProcessA);
DO_HOOK (NULL, CreateProcessW);
}
-#endif /* USE_API_HOOK */
}
/* This thread function handles the master control pipe. It waits for a