diff options
author | Takashi Yano <takashi.yano@nifty.ne.jp> | 2024-07-06 13:50:51 +0900 |
---|---|---|
committer | Takashi Yano <takashi.yano@nifty.ne.jp> | 2024-07-06 14:02:26 +0900 |
commit | baf2764dca435d77fdd25e19146c831214a2da73 (patch) | |
tree | 72255f2bada09ffa8e137dfdfe46ae73abb3ba64 /winsup | |
parent | f7a77d014693a88b8a3dbecfd792956e99a7323e (diff) | |
download | newlib-baf2764dca435d77fdd25e19146c831214a2da73.zip newlib-baf2764dca435d77fdd25e19146c831214a2da73.tar.gz newlib-baf2764dca435d77fdd25e19146c831214a2da73.tar.bz2 |
Cygwin: console: Fixes an issue that tmux can not run on the console.
After the commit c77a5689f7bd, tmux can not run on the console.
This patch replaces the countermeasure for the race issue between
console setup and close with another mechanism using a mutex.
Fixes: c77a5689f7bd ("Cygwin: console: Do not unmap shared console memory belonging to ctty.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/fhandler/console.cc | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc index 7945a32..a870b74 100644 --- a/winsup/cygwin/fhandler/console.cc +++ b/winsup/cygwin/fhandler/console.cc @@ -48,6 +48,9 @@ details. */ con.b.srWindow.Top + con.scroll_region.Bottom) #define con_is_legacy (shared_console_info[unit] && con.is_legacy) +static HANDLE NO_COPY shared_info_mutex; +static int NO_COPY shared_info_state; + #define CONS_THREAD_SYNC "cygcons.thread_sync" static bool NO_COPY master_thread_started = false; @@ -665,6 +668,12 @@ fhandler_console::set_unit () else if (myself->ctty != CTTY_UNINITIALIZED) unit = device::minor (myself->ctty); + if (!shared_info_mutex) + shared_info_mutex = CreateMutex (&sec_none_nih, FALSE, NULL); + + WaitForSingleObject (shared_info_mutex, INFINITE); + shared_info_state++; + if (shared_console_info[unit]) ; /* Do nothing */ else if (generic_console @@ -698,6 +707,8 @@ fhandler_console::set_unit () } } } + ReleaseMutex (shared_info_mutex); + if (shared_console_info[unit]) { devset = (fh_devices) shared_console_info[unit]->tty_min_state.getntty (); @@ -1963,11 +1974,13 @@ fhandler_console::close () CloseHandle (output_mutex); output_mutex = NULL; - if (shared_console_info[unit] && myself->ctty != tc ()->ntty) + WaitForSingleObject (shared_info_mutex, INFINITE); + if (--shared_info_state == 0 && shared_console_info[unit]) { UnmapViewOfFile ((void *) shared_console_info[unit]); shared_console_info[unit] = NULL; } + ReleaseMutex (shared_info_mutex); return 0; } |