Cygwin: console, pty: Prevent error in legacy console mode.
This commit is contained in:
parent
e5db0d2fe0
commit
3880efb283
@ -859,6 +859,7 @@ environ_init (char **envp, int envc)
|
|||||||
__endtry
|
__endtry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sawTERM = 0;
|
||||||
|
|
||||||
char ** __reg2
|
char ** __reg2
|
||||||
win32env_to_cygenv (PWCHAR rawenv, bool posify)
|
win32env_to_cygenv (PWCHAR rawenv, bool posify)
|
||||||
@ -868,7 +869,6 @@ win32env_to_cygenv (PWCHAR rawenv, bool posify)
|
|||||||
int envc;
|
int envc;
|
||||||
char *newp;
|
char *newp;
|
||||||
int i;
|
int i;
|
||||||
int sawTERM = 0;
|
|
||||||
const char cygterm[] = "TERM=cygwin";
|
const char cygterm[] = "TERM=cygwin";
|
||||||
const char xterm[] = "TERM=xterm-256color";
|
const char xterm[] = "TERM=xterm-256color";
|
||||||
char *tmpbuf = tp.t_get ();
|
char *tmpbuf = tp.t_get ();
|
||||||
|
@ -1831,6 +1831,7 @@ enum cltype
|
|||||||
class dev_console
|
class dev_console
|
||||||
{
|
{
|
||||||
pid_t owner;
|
pid_t owner;
|
||||||
|
bool is_legacy;
|
||||||
|
|
||||||
WORD default_color, underline_color, dim_color;
|
WORD default_color, underline_color, dim_color;
|
||||||
|
|
||||||
|
@ -309,7 +309,7 @@ fhandler_console::set_cursor_maybe ()
|
|||||||
{
|
{
|
||||||
con.fillin (get_output_handle ());
|
con.fillin (get_output_handle ());
|
||||||
/* Nothing to do for xterm compatible mode. */
|
/* Nothing to do for xterm compatible mode. */
|
||||||
if (wincap.has_con_24bit_colors ())
|
if (wincap.has_con_24bit_colors () && !con.is_legacy)
|
||||||
return;
|
return;
|
||||||
if (con.dwLastCursorPosition.X != con.b.dwCursorPosition.X ||
|
if (con.dwLastCursorPosition.X != con.b.dwCursorPosition.X ||
|
||||||
con.dwLastCursorPosition.Y != con.b.dwCursorPosition.Y)
|
con.dwLastCursorPosition.Y != con.b.dwCursorPosition.Y)
|
||||||
@ -349,7 +349,7 @@ fhandler_console::send_winch_maybe ()
|
|||||||
{
|
{
|
||||||
con.scroll_region.Top = 0;
|
con.scroll_region.Top = 0;
|
||||||
con.scroll_region.Bottom = -1;
|
con.scroll_region.Bottom = -1;
|
||||||
if (wincap.has_con_24bit_colors ())
|
if (wincap.has_con_24bit_colors () && !con.is_legacy)
|
||||||
fix_tab_position (get_output_handle (), con.dwWinSize.X);
|
fix_tab_position (get_output_handle (), con.dwWinSize.X);
|
||||||
get_ttyp ()->kill_pgrp (SIGWINCH);
|
get_ttyp ()->kill_pgrp (SIGWINCH);
|
||||||
return true;
|
return true;
|
||||||
@ -483,7 +483,7 @@ sig_exit:
|
|||||||
fhandler_console::input_states
|
fhandler_console::input_states
|
||||||
fhandler_console::process_input_message (void)
|
fhandler_console::process_input_message (void)
|
||||||
{
|
{
|
||||||
if (wincap.has_con_24bit_colors ())
|
if (wincap.has_con_24bit_colors () && !con.is_legacy)
|
||||||
{
|
{
|
||||||
DWORD dwMode;
|
DWORD dwMode;
|
||||||
/* Enable xterm compatible mode in input */
|
/* Enable xterm compatible mode in input */
|
||||||
@ -589,7 +589,8 @@ fhandler_console::process_input_message (void)
|
|||||||
}
|
}
|
||||||
/* Allow Ctrl-Space to emit ^@ */
|
/* Allow Ctrl-Space to emit ^@ */
|
||||||
else if (input_rec[i].Event.KeyEvent.wVirtualKeyCode
|
else if (input_rec[i].Event.KeyEvent.wVirtualKeyCode
|
||||||
== (wincap.has_con_24bit_colors () ? '2' : VK_SPACE)
|
== ((wincap.has_con_24bit_colors () && !con.is_legacy) ?
|
||||||
|
'2' : VK_SPACE)
|
||||||
&& (ctrl_key_state & CTRL_PRESSED)
|
&& (ctrl_key_state & CTRL_PRESSED)
|
||||||
&& !(ctrl_key_state & ALT_PRESSED))
|
&& !(ctrl_key_state & ALT_PRESSED))
|
||||||
toadd = "";
|
toadd = "";
|
||||||
@ -1023,17 +1024,28 @@ fhandler_console::open (int flags, mode_t)
|
|||||||
/* Enable xterm compatible mode in output */
|
/* Enable xterm compatible mode in output */
|
||||||
GetConsoleMode (get_output_handle (), &dwMode);
|
GetConsoleMode (get_output_handle (), &dwMode);
|
||||||
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||||
SetConsoleMode (get_output_handle (), dwMode);
|
if (!SetConsoleMode (get_output_handle (), dwMode))
|
||||||
|
con.is_legacy = true;
|
||||||
|
else
|
||||||
|
con.is_legacy = false;
|
||||||
/* Enable xterm compatible mode in input */
|
/* Enable xterm compatible mode in input */
|
||||||
|
if (!con.is_legacy)
|
||||||
|
{
|
||||||
GetConsoleMode (get_handle (), &dwMode);
|
GetConsoleMode (get_handle (), &dwMode);
|
||||||
dwMode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
|
dwMode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
|
||||||
SetConsoleMode (get_handle (), dwMode);
|
if (!SetConsoleMode (get_handle (), dwMode))
|
||||||
|
con.is_legacy = true;
|
||||||
|
}
|
||||||
|
extern int sawTERM;
|
||||||
|
if (con.is_legacy && !sawTERM)
|
||||||
|
setenv ("TERM", "cygwin", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD cflags;
|
DWORD cflags;
|
||||||
if (GetConsoleMode (get_handle (), &cflags))
|
if (GetConsoleMode (get_handle (), &cflags))
|
||||||
SetConsoleMode (get_handle (), ENABLE_WINDOW_INPUT
|
SetConsoleMode (get_handle (), ENABLE_WINDOW_INPUT
|
||||||
| (wincap.has_con_24bit_colors () ? 0 : ENABLE_MOUSE_INPUT)
|
| ((wincap.has_con_24bit_colors () && !con.is_legacy) ?
|
||||||
|
0 : ENABLE_MOUSE_INPUT)
|
||||||
| cflags);
|
| cflags);
|
||||||
|
|
||||||
debug_printf ("opened conin$ %p, conout$ %p", get_handle (),
|
debug_printf ("opened conin$ %p, conout$ %p", get_handle (),
|
||||||
@ -1062,7 +1074,7 @@ fhandler_console::close ()
|
|||||||
output_mutex = NULL;
|
output_mutex = NULL;
|
||||||
|
|
||||||
if (shared_console_info && getpid () == con.owner &&
|
if (shared_console_info && getpid () == con.owner &&
|
||||||
wincap.has_con_24bit_colors ())
|
wincap.has_con_24bit_colors () && !con.is_legacy)
|
||||||
{
|
{
|
||||||
DWORD dwMode;
|
DWORD dwMode;
|
||||||
/* Disable xterm compatible mode in input */
|
/* Disable xterm compatible mode in input */
|
||||||
@ -1209,7 +1221,7 @@ fhandler_console::output_tcsetattr (int, struct termios const *t)
|
|||||||
acquire_output_mutex (INFINITE);
|
acquire_output_mutex (INFINITE);
|
||||||
DWORD flags = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
|
DWORD flags = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
|
||||||
/* If system has 24 bit color capability, use xterm compatible mode. */
|
/* If system has 24 bit color capability, use xterm compatible mode. */
|
||||||
if (wincap.has_con_24bit_colors ())
|
if (wincap.has_con_24bit_colors () && !con.is_legacy)
|
||||||
{
|
{
|
||||||
flags |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
flags |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||||
if (!(t->c_oflag & OPOST) || !(t->c_oflag & ONLCR))
|
if (!(t->c_oflag & OPOST) || !(t->c_oflag & ONLCR))
|
||||||
@ -1274,9 +1286,10 @@ fhandler_console::input_tcsetattr (int, struct termios const *t)
|
|||||||
}
|
}
|
||||||
|
|
||||||
flags |= ENABLE_WINDOW_INPUT |
|
flags |= ENABLE_WINDOW_INPUT |
|
||||||
(wincap.has_con_24bit_colors () ? 0 : ENABLE_MOUSE_INPUT);
|
((wincap.has_con_24bit_colors () && !con.is_legacy) ?
|
||||||
|
0 : ENABLE_MOUSE_INPUT);
|
||||||
/* if system has 24 bit color capability, use xterm compatible mode. */
|
/* if system has 24 bit color capability, use xterm compatible mode. */
|
||||||
if (wincap.has_con_24bit_colors ())
|
if (wincap.has_con_24bit_colors () && !con.is_legacy)
|
||||||
flags |= ENABLE_VIRTUAL_TERMINAL_INPUT;
|
flags |= ENABLE_VIRTUAL_TERMINAL_INPUT;
|
||||||
|
|
||||||
int res;
|
int res;
|
||||||
@ -1650,7 +1663,7 @@ bool fhandler_console::write_console (PWCHAR buf, DWORD len, DWORD& done)
|
|||||||
{
|
{
|
||||||
bool need_fix_tab_position = false;
|
bool need_fix_tab_position = false;
|
||||||
/* Check if screen will be alternated. */
|
/* Check if screen will be alternated. */
|
||||||
if (wincap.has_con_24bit_colors ()
|
if (wincap.has_con_24bit_colors () && !con.is_legacy
|
||||||
&& memmem (buf, len*sizeof (WCHAR), L"\033[?1049", 7*sizeof (WCHAR)))
|
&& memmem (buf, len*sizeof (WCHAR), L"\033[?1049", 7*sizeof (WCHAR)))
|
||||||
need_fix_tab_position = true;
|
need_fix_tab_position = true;
|
||||||
|
|
||||||
@ -2498,7 +2511,8 @@ fhandler_console::write_normal (const unsigned char *src,
|
|||||||
memset (&ps, 0, sizeof ps);
|
memset (&ps, 0, sizeof ps);
|
||||||
while (found < end
|
while (found < end
|
||||||
&& found - src < CONVERT_LIMIT
|
&& found - src < CONVERT_LIMIT
|
||||||
&& (wincap.has_con_24bit_colors () || base_chars[*found] == NOR) )
|
&& ((wincap.has_con_24bit_colors () && !con.is_legacy)
|
||||||
|
|| base_chars[*found] == NOR) )
|
||||||
{
|
{
|
||||||
switch (ret = f_mbtowc (_REENT, NULL, (const char *) found,
|
switch (ret = f_mbtowc (_REENT, NULL, (const char *) found,
|
||||||
end - found, &ps))
|
end - found, &ps))
|
||||||
@ -2958,7 +2972,7 @@ fhandler_console::fixup_after_fork_exec (bool execing)
|
|||||||
{
|
{
|
||||||
set_unit ();
|
set_unit ();
|
||||||
setup_io_mutex ();
|
setup_io_mutex ();
|
||||||
if (wincap.has_con_24bit_colors ())
|
if (wincap.has_con_24bit_colors () && !con.is_legacy)
|
||||||
{
|
{
|
||||||
DWORD dwMode;
|
DWORD dwMode;
|
||||||
/* Disable xterm compatible mode in input */
|
/* Disable xterm compatible mode in input */
|
||||||
|
@ -26,6 +26,7 @@ details. */
|
|||||||
#include <asm/socket.h>
|
#include <asm/socket.h>
|
||||||
#include "cygwait.h"
|
#include "cygwait.h"
|
||||||
#include "tls_pbuf.h"
|
#include "tls_pbuf.h"
|
||||||
|
#include "registry.h"
|
||||||
|
|
||||||
#define ALWAYS_USE_PCON false
|
#define ALWAYS_USE_PCON false
|
||||||
#define USE_API_HOOK true
|
#define USE_API_HOOK true
|
||||||
@ -3104,6 +3105,19 @@ is_running_as_service (void)
|
|||||||
bool
|
bool
|
||||||
fhandler_pty_master::setup_pseudoconsole ()
|
fhandler_pty_master::setup_pseudoconsole ()
|
||||||
{
|
{
|
||||||
|
/* If the legacy console mode is enabled, pseudo console seems
|
||||||
|
not to work as expected. To determine console mode, registry
|
||||||
|
key ForceV2 in HKEY_CURRENT_USER\Console is checked. */
|
||||||
|
reg_key reg (HKEY_CURRENT_USER, KEY_READ, L"Console", NULL);
|
||||||
|
if (reg.error ())
|
||||||
|
return false;
|
||||||
|
if (reg.get_dword (L"ForceV2", 1) == 0)
|
||||||
|
{
|
||||||
|
termios_printf ("Pseudo console is disabled "
|
||||||
|
"because the legacy console mode is enabled.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* Pseudo console supprot is realized using a tricky technic.
|
/* Pseudo console supprot is realized using a tricky technic.
|
||||||
PTY need the pseudo console handles, however, they cannot
|
PTY need the pseudo console handles, however, they cannot
|
||||||
be retrieved by normal procedure. Therefore, run a helper
|
be retrieved by normal procedure. Therefore, run a helper
|
||||||
|
Loading…
x
Reference in New Issue
Block a user