Skip to content

Commit

Permalink
Cygwin: console: Add missing input_mutex guard.
Browse files Browse the repository at this point in the history
- Setting con.disable_master_thread flag should be guarded by
  input_mutex, however, it was not. This patch fixes that.
  • Loading branch information
tyan0 committed Jul 28, 2022
1 parent 3339563 commit d4aacd5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions winsup/cygwin/fhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2298,6 +2298,7 @@ class fhandler_console: public fhandler_termios
static void cleanup_for_non_cygwin_app (handle_set_t *p);
static void set_console_mode_to_native ();
bool need_console_handler ();
static void set_disable_master_thread (bool x);

friend tty_min * tty_list::get_cttyp ();
};
Expand Down
23 changes: 17 additions & 6 deletions winsup/cygwin/fhandler_console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ fhandler_console::setup_for_non_cygwin_app ()
(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 ());
con.disable_master_thread = true;
set_disable_master_thread (true);
}

void
Expand All @@ -807,7 +807,7 @@ fhandler_console::cleanup_for_non_cygwin_app (handle_set_t *p)
(con.owner == myself->pid) ? tty::restore : tty::cygwin;
set_output_mode (conmode, ti, p);
set_input_mode (conmode, ti, p);
con.disable_master_thread = (con.owner == myself->pid);
set_disable_master_thread (con.owner == myself->pid);
}

/* Return the tty structure associated with a given tty number. If the
Expand Down Expand Up @@ -986,7 +986,7 @@ fhandler_console::bg_check (int sig, bool dontsignal)
if (sig == SIGTTIN)
{
set_input_mode (tty::cygwin, &tc ()->ti, get_handle_set ());
con.disable_master_thread = false;
set_disable_master_thread (false);
}
if (sig == SIGTTOU)
set_output_mode (tty::cygwin, &tc ()->ti, get_handle_set ());
Expand Down Expand Up @@ -1717,7 +1717,7 @@ fhandler_console::post_open_setup (int fd)
if (fd == 0)
{
set_input_mode (tty::cygwin, &get_ttyp ()->ti, &handle_set);
con.disable_master_thread = false;
set_disable_master_thread (false);
}
else if (fd == 1 || fd == 2)
set_output_mode (tty::cygwin, &get_ttyp ()->ti, &handle_set);
Expand Down Expand Up @@ -1745,7 +1745,7 @@ fhandler_console::close ()
/* 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);
con.disable_master_thread = true;
set_disable_master_thread (true);
}
}

Expand Down Expand Up @@ -3971,7 +3971,7 @@ fhandler_console::set_console_mode_to_native ()
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 ());
con.disable_master_thread = true;
set_disable_master_thread (true);
break;
}
}
Expand Down Expand Up @@ -4294,3 +4294,14 @@ fhandler_console::need_console_handler ()
{
return con.disable_master_thread || con.master_thread_suspended;
}

void
fhandler_console::set_disable_master_thread (bool x)
{
if (cygheap->ctty->get_major () != DEV_CONS_MAJOR)
return;
fhandler_console *cons = (fhandler_console *) cygheap->ctty;
cons->acquire_input_mutex (mutex_timeout);
con.disable_master_thread = x;
cons->release_input_mutex ();
}

0 comments on commit d4aacd5

Please sign in to comment.