void set_cursor_maybe ();
static bool create_invisible_console_workaround (bool force);
static console_state *open_shared_console (HWND, HANDLE&, bool&);
- void fix_tab_position (void);
+ static void fix_tab_position (HANDLE h);
+
+/* console mode calls */
+ const handle_set_t *get_handle_set (void) {return &handle_set;}
+ static void set_input_mode (tty::cons_mode m, const termios *t,
+ const handle_set_t *p);
+ static void set_output_mode (tty::cons_mode m, const termios *t,
+ const handle_set_t *p);
public:
static pid_t tc_getpgid ()
return fh;
}
input_states process_input_message ();
+ bg_check_types bg_check (int sig, bool dontsignal = false);
void setup_io_mutex (void);
DWORD __acquire_input_mutex (const char *fn, int ln, DWORD ms);
void __release_input_mutex (const char *fn, int ln);
size_t &raixput ();
size_t &rabuflen ();
- const handle_set_t *get_handle_set (void) {return &handle_set;}
void get_duplicated_handle_set (handle_set_t *p);
static void close_handle_set (handle_set_t *p);
- static void set_input_mode (tty::cons_mode m, const termios *t,
- const handle_set_t *p);
- static void set_output_mode (tty::cons_mode m, const termios *t,
- const handle_set_t *p);
-
static void cons_master_thread (handle_set_t *p, tty *ttyp);
pid_t get_owner (void) { return shared_console_info->con.owner; }
+ void setup_console_for_non_cygwin_app ();
+ void cleanup_console_for_non_cygwin_app ();
+ static void set_console_mode_to_native ();
friend tty_min * tty_list::get_cttyp ();
};
con.scroll_region.Top = 0;
con.scroll_region.Bottom = -1;
if (wincap.has_con_24bit_colors () && !con_is_legacy)
- { /* Fix tab position */
- /* Re-setting ENABLE_VIRTUAL_TERMINAL_PROCESSING
- fixes the tab position. */
- set_output_mode (tty::restore, &ti, p);
- set_output_mode (tty::cygwin, &ti, p);
- }
+ fix_tab_position (p->output_handle);
ttyp->kill_pgrp (SIGWINCH);
}
processed = true;
ReleaseMutex (p->output_mutex);
}
+static fhandler_console::handle_set_t NO_COPY duplicated_handle_set;
+
+void
+fhandler_console::setup_console_for_non_cygwin_app ()
+{
+ /* Setting-up console mode for non-cygwin app. */
+ /* If conmode is set to tty::native for non-cygwin apps
+ in background, tty settings of the shell is reflected
+ to the console mode of the app. So, use tty::restore
+ for background process instead. */
+ tty::cons_mode conmode =
+ (get_ttyp ()->getpgid ()== myself->pgid) ? tty::native : tty::restore;
+ set_input_mode (conmode, &tc ()->ti, get_handle_set ());
+ set_output_mode (conmode, &tc ()->ti, get_handle_set ());
+ /* Console handles will be already closed by close_all_files()
+ when cleaning up, therefore, duplicate them here. */
+ get_duplicated_handle_set (&duplicated_handle_set);
+}
+
+void
+fhandler_console::cleanup_console_for_non_cygwin_app ()
+{
+ /* Cleaning-up console mode for non-cygwin app. */
+ /* conmode can be tty::restore when non-cygwin app is
+ exec'ed from login shell. */
+ tty::cons_mode conmode =
+ (con.owner == myself->pid) ? tty::restore : tty::cygwin;
+ set_output_mode (conmode, &tc ()->ti, &duplicated_handle_set);
+ set_input_mode (conmode, &tc ()->ti, &duplicated_handle_set);
+ close_handle_set (&duplicated_handle_set);
+}
+
/* Return the tty structure associated with a given tty number. If the
tty number is < 0, just return a dummy record. */
tty_min *
/* Workaround for a bug of windows xterm compatible mode. */
/* The horizontal tab positions are broken after resize. */
void
-fhandler_console::fix_tab_position (void)
+fhandler_console::fix_tab_position (HANDLE h)
{
/* Re-setting ENABLE_VIRTUAL_TERMINAL_PROCESSING
fixes the tab position. */
- set_output_mode (tty::restore, &get_ttyp ()->ti, &handle_set);
- set_output_mode (tty::cygwin, &get_ttyp ()->ti, &handle_set);
+ DWORD mode;
+ GetConsoleMode (h, &mode);
+ SetConsoleMode (h, mode & ~ENABLE_VIRTUAL_TERMINAL_PROCESSING);
+ SetConsoleMode (h, mode);
}
bool
con.scroll_region.Top = 0;
con.scroll_region.Bottom = -1;
if (wincap.has_con_24bit_colors () && !con_is_legacy)
- fix_tab_position ();
+ fix_tab_position (get_output_handle ());
get_ttyp ()->kill_pgrp (SIGWINCH);
return true;
}
|| con.use_mouse >= 3));
}
+
+bg_check_types
+fhandler_console::bg_check (int sig, bool dontsignal)
+{
+ /* Setting-up console mode for cygwin app. This is necessary if the
+ cygwin app and other non-cygwin apps are started simultaneously
+ in the same process group. */
+ if (sig == SIGTTIN)
+ set_input_mode (tty::cygwin, &tc ()->ti, get_handle_set ());
+ if (sig == SIGTTOU)
+ set_output_mode (tty::cygwin, &tc ()->ti, get_handle_set ());
+
+ return fhandler_termios::bg_check (sig, dontsignal);
+}
+
void __reg3
fhandler_console::read (void *pv, size_t& buflen)
{
DWORD timeout = is_nonblocking () ? 0 : INFINITE;
- set_input_mode (tty::cygwin, &get_ttyp ()->ti, &handle_set);
-
while (!input_ready && !get_cons_readahead_valid ())
{
int bgres;
void
fhandler_console::post_open_setup (int fd)
{
+ /* Setting-up console mode for cygwin app started from non-cygwin app. */
if (fd == 0)
set_input_mode (tty::cygwin, &get_ttyp ()->ti, &handle_set);
else if (fd == 1 || fd == 2)
if ((NT_SUCCESS (status) && obi.HandleCount == 1)
|| myself->pid == con.owner)
{
+ /* Cleaning-up console mode for cygwin apps. */
set_output_mode (tty::restore, &get_ttyp ()->ti, &handle_set);
set_input_mode (tty::restore, &get_ttyp ()->ti, &handle_set);
}
}
/* Call fix_tab_position() if screen has been alternated. */
if (need_fix_tab_position)
- fix_tab_position ();
+ fix_tab_position (get_output_handle ());
}
break;
case 'p':
acquire_attach_mutex (mutex_timeout);
push_process_state process_state (PID_TTYOU);
- set_output_mode (tty::cygwin, &get_ttyp ()->ti, &handle_set);
-
acquire_output_mutex (mutex_timeout);
/* Run and check for ansi sequences */
}
static bool NO_COPY gdb_inferior_noncygwin = false;
-static void
-set_console_mode_to_native ()
+
+void
+fhandler_console::set_console_mode_to_native ()
{
+ /* Setting-up console mode for non-cygwin app started by GDB. This is
+ called from hooked CreateProcess() and ContinueDebugEvent(). */
cygheap_fdenum cfd (false);
while (cfd.next () >= 0)
if (cfd->get_major () == DEV_CONS_MAJOR)
fhandler_console *cons = (fhandler_console *) (fhandler_base *) cfd;
if (cons->get_device () == cons->tc ()->getntty ())
{
- termios *cons_ti = &((tty *) cons->tc ())->ti;
- fhandler_console::set_input_mode (tty::native, cons_ti,
- cons->get_handle_set ());
- fhandler_console::set_output_mode (tty::native, cons_ti,
- cons->get_handle_set ());
+ termios *cons_ti = &cons->tc ()->ti;
+ set_input_mode (tty::native, cons_ti, cons->get_handle_set ());
+ set_output_mode (tty::native, cons_ti, cons->get_handle_set ());
break;
}
}
mutex_timeout = 0; /* to avoid deadlock in GDB */
gdb_inferior_noncygwin = !fhandler_termios::path_iscygexec_a (n, c);
if (gdb_inferior_noncygwin)
- set_console_mode_to_native ();
+ fhandler_console::set_console_mode_to_native ();
return CreateProcessA_Orig (n, c, pa, ta, inh, f, e, d, si, pi);
}
mutex_timeout = 0; /* to avoid deadlock in GDB */
gdb_inferior_noncygwin = !fhandler_termios::path_iscygexec_w (n, c);
if (gdb_inferior_noncygwin)
- set_console_mode_to_native ();
+ fhandler_console::set_console_mode_to_native ();
return CreateProcessW_Orig (n, c, pa, ta, inh, f, e, d, si, pi);
}
(DWORD p, DWORD t, DWORD s)
{
if (gdb_inferior_noncygwin)
- set_console_mode_to_native ();
+ fhandler_console::set_console_mode_to_native ();
return ContinueDebugEvent_Orig (p, t, s);
}
fhandler_pty_slave *ptys_primary = NULL;
fhandler_console *cons_native = NULL;
- termios *cons_ti = NULL;
- pid_t cons_owner = 0;
for (int i = 0; i < 3; i ++)
{
const int chk_order[] = {1, 0, 2};
{
if (!iscygwin () && cons_native == NULL)
{
- fhandler_console *cons = (fhandler_console *) fh;
- cons_native = cons;
- cons_ti = &((tty *)cons->tc ())->ti;
- cons_owner = cons->get_owner ();
- tty::cons_mode conmode =
- (ctty_pgid && ctty_pgid == myself->pgid) ?
- tty::native : tty::restore;
- fhandler_console::set_input_mode (conmode,
- cons_ti, cons->get_handle_set ());
- fhandler_console::set_output_mode (conmode,
- cons_ti, cons->get_handle_set ());
+ cons_native = (fhandler_console *) fh;
+ cons_native->setup_console_for_non_cygwin_app ();
}
}
}
- struct fhandler_console::handle_set_t cons_handle_set = { 0, };
- if (cons_native)
- /* Console handles will be closed by close_all_files(),
- therefore, duplicate them here */
- cons_native->get_duplicated_handle_set (&cons_handle_set);
if (!iscygwin ())
{
CloseHandle (ptys_pcon_mutex);
}
if (cons_native)
- {
- tty::cons_mode conmode =
- cons_owner == myself->pid ? tty::restore : tty::cygwin;
- fhandler_console::set_output_mode (conmode, cons_ti,
- &cons_handle_set);
- fhandler_console::set_input_mode (conmode, cons_ti,
- &cons_handle_set);
- fhandler_console::close_handle_set (&cons_handle_set);
- }
+ cons_native->cleanup_console_for_non_cygwin_app ();
myself.exit (EXITCODE_NOSET);
break;
case _P_WAIT:
CloseHandle (ptys_pcon_mutex);
}
if (cons_native)
- {
- tty::cons_mode conmode =
- cons_owner == myself->pid ? tty::restore : tty::cygwin;
- fhandler_console::set_output_mode (conmode, cons_ti,
- &cons_handle_set);
- fhandler_console::set_input_mode (conmode, cons_ti,
- &cons_handle_set);
- fhandler_console::close_handle_set (&cons_handle_set);
- }
+ cons_native->cleanup_console_for_non_cygwin_app ();
break;
case _P_DETACH:
res = 0; /* Lost all memory of this child. */