aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin
diff options
context:
space:
mode:
authorTakashi Yano <takashi.yano@nifty.ne.jp>2024-11-05 20:20:21 +0900
committerTakashi Yano <takashi.yano@nifty.ne.jp>2024-11-05 20:42:58 +0900
commitdf0953aa298c0c6b92b8735c6a703239db36091d (patch)
tree85e77f360a39f0ffb746fb151a7a79a158826d42 /winsup/cygwin
parent37920d33accdc1f841da25c1ecd8d0ac35c41682 (diff)
downloadnewlib-df0953aa298c0c6b92b8735c6a703239db36091d.zip
newlib-df0953aa298c0c6b92b8735c6a703239db36091d.tar.gz
newlib-df0953aa298c0c6b92b8735c6a703239db36091d.tar.bz2
Cygwin: console: Fix open() failure when the console owner calls exec().
Currently, open() tries to attach to the console which is owned by the console owner process. However, when the owner process calls exec(), AttachConsole() to dwProcessId may sometimes fail due to unlucky timing. With this patch, open() tries to attach also to exec_dwProcessId if attaching to dwProcessId fails. That is, open() tries to attach to both the stub process and target process to prevent the above situation. Fixes: 3721a756b0d8 ("Cygwin: console: Make the console accessible from other terminals.") Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Diffstat (limited to 'winsup/cygwin')
-rw-r--r--winsup/cygwin/fhandler/console.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc
index 9cdc13d..ac47c83 100644
--- a/winsup/cygwin/fhandler/console.cc
+++ b/winsup/cygwin/fhandler/console.cc
@@ -85,6 +85,10 @@ fhandler_console::attach_console (pid_t owner, bool *err)
fhandler_pty_common::get_console_process_id (p->dwProcessId,
true, false, false);
if (!attached)
+ attached =
+ fhandler_pty_common::get_console_process_id (p->exec_dwProcessId,
+ true, false, false);
+ if (!attached)
{
resume_pid =
fhandler_pty_common::get_console_process_id (myself->dwProcessId,
@@ -92,6 +96,8 @@ fhandler_console::attach_console (pid_t owner, bool *err)
FreeConsole ();
BOOL r = AttachConsole (p->dwProcessId);
if (!r)
+ r = AttachConsole (p->exec_dwProcessId);
+ if (!r)
{
if (resume_pid)
AttachConsole (resume_pid);