From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Subject: [PATCH 3/5] Cygwin: pty: Make close_pseudoconsole() be a static member function.
Date: Fri, 15 Jan 2021 17:32:11 +0900 [thread overview]
Message-ID: <20210115083213.676-4-takashi.yano@nifty.ne.jp> (raw)
In-Reply-To: <20210115083213.676-1-takashi.yano@nifty.ne.jp>
- The function close_pseudoconsole() should be static so that it
can be safely called in spawn.cc even after the fhandler_pty_slave
instance has been deleted. That is, there is a problem with the
current code. This patch fixes the issue.
---
winsup/cygwin/fhandler.h | 3 ++-
winsup/cygwin/fhandler_tty.cc | 22 ++++++++++++----------
winsup/cygwin/spawn.cc | 6 ++++--
3 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 45ac17af2..2077b5245 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -2339,12 +2339,13 @@ class fhandler_pty_slave: public fhandler_pty_common
return fh;
}
bool setup_pseudoconsole (STARTUPINFOEXW *si, bool nopcon);
- void close_pseudoconsole (void);
+ static void close_pseudoconsole (tty *ttyp);
bool term_has_pcon_cap (const WCHAR *env);
void set_switch_to_pcon (void);
void reset_switch_to_pcon (void);
void mask_switch_to_pcon_in (bool mask);
void setup_locale (void);
+ tty *get_ttyp () { return (tty *) tc (); } /* Override as public */
};
#define __ptsname(buf, unit) __small_sprintf ((buf), "/dev/pty%d", (unit))
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 8ff74cdde..0c92f41d4 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -2563,21 +2563,23 @@ fallback:
return false;
}
+/* The function close_pseudoconsole() should be static so that it can
+ be called even after the fhandler_pty_slave instance is deleted. */
void
-fhandler_pty_slave::close_pseudoconsole (void)
+fhandler_pty_slave::close_pseudoconsole (tty *ttyp)
{
- if (get_ttyp ()->h_pseudo_console)
+ if (ttyp->h_pseudo_console)
{
- get_ttyp ()->wait_pcon_fwd ();
- HPCON_INTERNAL *hp = (HPCON_INTERNAL *) get_ttyp ()->h_pseudo_console;
+ ttyp->wait_pcon_fwd ();
+ HPCON_INTERNAL *hp = (HPCON_INTERNAL *) ttyp->h_pseudo_console;
HANDLE tmp = hp->hConHostProcess;
- ClosePseudoConsole (get_ttyp ()->h_pseudo_console);
+ ClosePseudoConsole (ttyp->h_pseudo_console);
CloseHandle (tmp);
- get_ttyp ()->h_pseudo_console = NULL;
- get_ttyp ()->switch_to_pcon_in = false;
- get_ttyp ()->pcon_pid = 0;
- get_ttyp ()->pcon_start = false;
- get_ttyp ()->do_not_resize_pcon = false;
+ ttyp->h_pseudo_console = NULL;
+ ttyp->switch_to_pcon_in = false;
+ ttyp->pcon_pid = 0;
+ ttyp->pcon_start = false;
+ ttyp->do_not_resize_pcon = false;
}
}
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 94909df4c..bf1b08057 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -664,6 +664,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
init_console_handler (myself->ctty > 0);
bool enable_pcon = false;
+ tty *ptys_ttyp = NULL;
STARTUPINFOEXW si_pcon;
ZeroMemory (&si_pcon, sizeof (si_pcon));
STARTUPINFOW *si_tmp = &si;
@@ -677,6 +678,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
c_flags |= EXTENDED_STARTUPINFO_PRESENT;
si_tmp = &si_pcon.StartupInfo;
enable_pcon = true;
+ ptys_ttyp = ptys_primary->get_ttyp ();
}
}
@@ -954,7 +956,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
if (enable_pcon)
{
WaitForSingleObject (pi.hProcess, INFINITE);
- ptys_primary->close_pseudoconsole ();
+ fhandler_pty_slave::close_pseudoconsole (ptys_ttyp);
}
else if (cons_native)
{
@@ -973,7 +975,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
if (waitpid (cygpid, &res, 0) != cygpid)
res = -1;
if (enable_pcon)
- ptys_primary->close_pseudoconsole ();
+ fhandler_pty_slave::close_pseudoconsole (ptys_ttyp);
else if (cons_native)
{
fhandler_console::request_xterm_mode_output (true,
--
2.30.0
next prev parent reply other threads:[~2021-01-15 8:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-15 8:32 [PATCH 0/5] Some revisions for pty and console code Takashi Yano
2021-01-15 8:32 ` [PATCH 1/5] Cygwin: pty: Add workaround for rlwrap 0.40 or later Takashi Yano
2021-01-15 8:32 ` [PATCH 2/5] Cygwin: console: Revise the code to switch xterm mode Takashi Yano
2021-01-15 8:32 ` Takashi Yano [this message]
2021-01-15 8:32 ` [PATCH 4/5] Cygwin: pty: Prevent pty from changing code page of parent console Takashi Yano
2021-01-18 10:23 ` Corinna Vinschen
2021-01-18 11:23 ` Takashi Yano
2021-01-15 8:32 ` [PATCH 5/5] Cygwin: pty: Make master thread functions be static Takashi Yano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210115083213.676-4-takashi.yano@nifty.ne.jp \
--to=takashi.yano@nifty.ne.jp \
--cc=cygwin-patches@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).