From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 26C82385841C; Sat, 19 Aug 2023 06:08:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26C82385841C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1692425334; bh=nR6Bkkpr6/IQ71uy32EntytKo5f2BcC8zzvTP3RumVM=; h=From:To:Subject:Date:From; b=N/WG6tRu6/tLu9tcJTT8TrajNCKDZuUZRQFG+OzW31A9qu3+FWpYmGtqTJ6x6Cef8 cYUHcT/6ki4Cc8GwsTdMQnu6BqcUsmcvtJ5RWV3/GCpK1nY6YMqphnq4m9w6voAwQA COMDlKqP9HiRTMeICnL4c7CmplM9phnRNy53lrxQ= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: pty: Fix failure to clear switch_to_nat_pipe flag. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 7ba103eb1a95703c7803e4ca48e6ba5c8e1f3d56 X-Git-Newrev: 90d3b16d2b93d573501394d88538c99335edc343 Message-Id: <20230819060854.26C82385841C@sourceware.org> Date: Sat, 19 Aug 2023 06:08:54 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D90d3b16d2b9= 3d573501394d88538c99335edc343 commit 90d3b16d2b93d573501394d88538c99335edc343 Author: Takashi Yano Date: Sat Aug 19 14:10:16 2023 +0900 Cygwin: pty: Fix failure to clear switch_to_nat_pipe flag. =20 After the commit fbfea31dd9b9, switch_to_nat_pipe is not cleared properly when non-cygwin app is terminated in the case where the pseudo console is disabled. This is because get_winpid_to_hand_over() sometimes returns PID of cygwin process even though it should return only PID of non-cygwin process. This patch fixes the issue by adding a new argument which requests only PID of non-cygwin process to get_console_process_id(). =20 Fixes: fbfea31dd9b9 ("Cygwin: pty: Avoid cutting the branch the pty mas= ter is sitting on.") Signed-off-by: Takashi Yano Diff: --- winsup/cygwin/fhandler/pty.cc | 11 ++++++++--- winsup/cygwin/local_includes/fhandler.h | 3 ++- winsup/cygwin/release/3.4.9 | 6 ++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc index 607333f52..3f4bc56b5 100644 --- a/winsup/cygwin/fhandler/pty.cc +++ b/winsup/cygwin/fhandler/pty.cc @@ -85,7 +85,8 @@ inline static bool process_alive (DWORD pid); stub_only: return only stub process's pid of non-cygwin process. */ DWORD fhandler_pty_common::get_console_process_id (DWORD pid, bool match, - bool cygwin, bool stub_only) + bool cygwin, bool stub_only, + bool nat) { tmp_pathbuf tp; DWORD *list =3D (DWORD *) tp.c_get (); @@ -109,6 +110,8 @@ fhandler_pty_common::get_console_process_id (DWORD pid,= bool match, else { pinfo p (cygwin_pid (list[i])); + if (nat && !!p && !ISSTATE(p, PID_NOTCYGWIN)) + continue; if (!!p && p->exec_dwProcessId) { res_pri =3D stub_only ? p->exec_dwProcessId : list[i]; @@ -3511,9 +3514,11 @@ fhandler_pty_slave::get_winpid_to_hand_over (tty *tt= yp, { /* Search another native process which attaches to the same console = */ DWORD current_pid =3D myself->exec_dwProcessId ?: myself->dwProcessI= d; - switch_to =3D get_console_process_id (current_pid, false, true, true= ); + switch_to =3D get_console_process_id (current_pid, + false, true, true, true); if (!switch_to) - switch_to =3D get_console_process_id (current_pid, false, true, false); + switch_to =3D get_console_process_id (current_pid, + false, true, false, true); } return switch_to; } diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_= includes/fhandler.h index 03b51a7e4..9af5f716c 100644 --- a/winsup/cygwin/local_includes/fhandler.h +++ b/winsup/cygwin/local_includes/fhandler.h @@ -2399,7 +2399,8 @@ class fhandler_pty_common: public fhandler_termios void resize_pseudo_console (struct winsize *); static DWORD get_console_process_id (DWORD pid, bool match, bool cygwin =3D false, - bool stub_only =3D false); + bool stub_only =3D false, + bool nat =3D false); bool to_be_read_from_nat_pipe (void); static DWORD attach_console_temporarily (DWORD target_pid); static void resume_from_temporarily_attach (DWORD resume_pid); diff --git a/winsup/cygwin/release/3.4.9 b/winsup/cygwin/release/3.4.9 new file mode 100644 index 000000000..d089e5a9a --- /dev/null +++ b/winsup/cygwin/release/3.4.9 @@ -0,0 +1,6 @@ +Bug Fixes +--------- + +- Fix a bug introduced in cygwin 3.4.0 that switch_to_nat_pipe flag is + not cleared properly when non-cygwin app is terminated in the case + where pseudo console is not activated.