public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: console: Fix restoring console mode failure.
@ 2021-03-04  8:57 Takashi Yano
  2021-03-04 10:10 ` Takashi Yano
  0 siblings, 1 reply; 2+ messages in thread
From: Takashi Yano @ 2021-03-04  8:57 UTC (permalink / raw)
  To: cygwin-patches

- Restoring console mode fails in the following scenario.
   1) Start cygwin shell in command prompt.
   2) Run 'exec chcp.com'.
  This patch fixes the issue.
---
 winsup/cygwin/fhandler.h |  1 +
 winsup/cygwin/spawn.cc   | 14 ++++++++++----
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index ad90cf33d..9b85d1ee9 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -2251,6 +2251,7 @@ private:
 			       const handle_set_t *p);
 
   static void cons_master_thread (handle_set_t *p, tty *ttyp);
+  pid_t get_owner (void) { return shared_console_info->con.owner; }
 
   friend tty_min * tty_list::get_cttyp ();
 };
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 323630fcb..490675859 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -608,6 +608,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
       fhandler_pty_slave *ptys_primary = NULL;
       fhandler_console *cons_native = NULL;
       termios *cons_ti = NULL;
+      pid_t cons_owner = 0;
       for (int i = 0; i < 3; i ++)
 	{
 	  const int chk_order[] = {1, 0, 2};
@@ -628,6 +629,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
 		    {
 		      cons_native = cons;
 		      cons_ti = &((tty *)cons->tc ())->ti;
+		      cons_owner = cons->get_owner ();
 		    }
 		  if (fd == 0)
 		    fhandler_console::set_input_mode (tty::native,
@@ -1000,9 +1002,11 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
 	    }
 	  if (cons_native)
 	    {
-	      fhandler_console::set_output_mode (tty::cygwin, cons_ti,
+	      tty::cons_mode mode =
+		cons_owner == myself->pid ? tty::restore : tty::cygwin;
+	      fhandler_console::set_output_mode (mode, cons_ti,
 						 &cons_handle_set);
-	      fhandler_console::set_input_mode (tty::cygwin, cons_ti,
+	      fhandler_console::set_input_mode (mode, cons_ti,
 						&cons_handle_set);
 	      fhandler_console::close_handle_set (&cons_handle_set);
 	    }
@@ -1035,9 +1039,11 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
 	    }
 	  if (cons_native)
 	    {
-	      fhandler_console::set_output_mode (tty::cygwin, cons_ti,
+	      tty::cons_mode mode =
+		cons_owner == myself->pid ? tty::restore : tty::cygwin;
+	      fhandler_console::set_output_mode (mode, cons_ti,
 						 &cons_handle_set);
-	      fhandler_console::set_input_mode (tty::cygwin, cons_ti,
+	      fhandler_console::set_input_mode (mode, cons_ti,
 						&cons_handle_set);
 	      fhandler_console::close_handle_set (&cons_handle_set);
 	    }
-- 
2.30.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Cygwin: console: Fix restoring console mode failure.
  2021-03-04  8:57 [PATCH] Cygwin: console: Fix restoring console mode failure Takashi Yano
@ 2021-03-04 10:10 ` Takashi Yano
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Yano @ 2021-03-04 10:10 UTC (permalink / raw)
  To: cygwin-patches

On Thu,  4 Mar 2021 17:57:34 +0900
Takashi Yano wrote:
> - Restoring console mode fails in the following scenario.
>    1) Start cygwin shell in command prompt.
>    2) Run 'exec chcp.com'.
>   This patch fixes the issue.
> ---
>  winsup/cygwin/fhandler.h |  1 +
>  winsup/cygwin/spawn.cc   | 14 ++++++++++----
>  2 files changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
> index ad90cf33d..9b85d1ee9 100644
> --- a/winsup/cygwin/fhandler.h
> +++ b/winsup/cygwin/fhandler.h
> @@ -2251,6 +2251,7 @@ private:
>  			       const handle_set_t *p);
>  
>    static void cons_master_thread (handle_set_t *p, tty *ttyp);
> +  pid_t get_owner (void) { return shared_console_info->con.owner; }
>  
>    friend tty_min * tty_list::get_cttyp ();
>  };
> diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
> index 323630fcb..490675859 100644
> --- a/winsup/cygwin/spawn.cc
> +++ b/winsup/cygwin/spawn.cc
> @@ -608,6 +608,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
>        fhandler_pty_slave *ptys_primary = NULL;
>        fhandler_console *cons_native = NULL;
>        termios *cons_ti = NULL;
> +      pid_t cons_owner = 0;
>        for (int i = 0; i < 3; i ++)
>  	{
>  	  const int chk_order[] = {1, 0, 2};
> @@ -628,6 +629,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
>  		    {
>  		      cons_native = cons;
>  		      cons_ti = &((tty *)cons->tc ())->ti;
> +		      cons_owner = cons->get_owner ();
>  		    }
>  		  if (fd == 0)
>  		    fhandler_console::set_input_mode (tty::native,
> @@ -1000,9 +1002,11 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
>  	    }
>  	  if (cons_native)
>  	    {
> -	      fhandler_console::set_output_mode (tty::cygwin, cons_ti,
> +	      tty::cons_mode mode =
> +		cons_owner == myself->pid ? tty::restore : tty::cygwin;
> +	      fhandler_console::set_output_mode (mode, cons_ti,
>  						 &cons_handle_set);
> -	      fhandler_console::set_input_mode (tty::cygwin, cons_ti,
> +	      fhandler_console::set_input_mode (mode, cons_ti,
>  						&cons_handle_set);
>  	      fhandler_console::close_handle_set (&cons_handle_set);
>  	    }
> @@ -1035,9 +1039,11 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
>  	    }
>  	  if (cons_native)
>  	    {
> -	      fhandler_console::set_output_mode (tty::cygwin, cons_ti,
> +	      tty::cons_mode mode =
> +		cons_owner == myself->pid ? tty::restore : tty::cygwin;
> +	      fhandler_console::set_output_mode (mode, cons_ti,
>  						 &cons_handle_set);
> -	      fhandler_console::set_input_mode (tty::cygwin, cons_ti,
> +	      fhandler_console::set_input_mode (mode, cons_ti,
>  						&cons_handle_set);
>  	      fhandler_console::close_handle_set (&cons_handle_set);
>  	    }

The variable name 'mode' is already used therefore this code
overrides it. I will submit v2 patch since it is not so good.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-04 10:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-04  8:57 [PATCH] Cygwin: console: Fix restoring console mode failure Takashi Yano
2021-03-04 10:10 ` Takashi Yano

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).