Re: [PATCH 2/2] Cygwin: pty: Disable clear screen on new pty if TERM=dumb or emacs*.

2019-09-05 Thread Takashi Yano
On Wed, 4 Sep 2019 21:36:28 -0600
Brian Inglis wrote:
> So how do you tell the pseudo-console to generate only text not escape 
> sequences
> the recipient may not be prepared to deal with?

Unfortunately, no idea.

-- 
Takashi Yano 


[PATCH 0/1] Cygwin: pty: Fix potential state mismatch regarding pseudo console.

2019-09-05 Thread Takashi Yano
- PTY with pseudo console support sitll has problem which potentially
  cause state mismatch between state variable and real console state.
  This patch fixes this issue.

Takashi Yano (1):
  Cygwin: pty: Fix potential state mismatch regarding pseudo console.

 winsup/cygwin/dtable.cc | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

-- 
2.21.0



[PATCH 1/1] Cygwin: pty: Fix potential state mismatch regarding pseudo console.

2019-09-05 Thread Takashi Yano
- PTY with pseudo console support sitll has problem which potentially
  cause state mismatch between state variable and real console state.
  This patch fixes this issue.
---
 winsup/cygwin/dtable.cc | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index 4e9b6ed56..7b2e52005 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -159,14 +159,19 @@ dtable::stdio_init ()
{
  bool attached = !!fhandler_console::get_console_process_id
(ptys->getHelperProcessId (), true);
- if (!attached)
+ if (attached)
+   break;
+ else
{
  /* Not attached to pseudo console in fork() or spawn()
 by some reason. This happens if the executable is
 a windows GUI binary, such as mintty. */
  FreeConsole ();
  if (AttachConsole (ptys->getHelperProcessId ()))
-   break;
+   {
+ ptys->fixup_after_attach (false);
+ break;
+   }
}
}
}
-- 
2.21.0



Re: [PATCH v2 0/1] Disable clear screen on new pty if TERM=dumb or emacs*.

2019-09-05 Thread Corinna Vinschen
On Sep  5 09:24, Takashi Yano wrote:
> - Pseudo console support introduced by commit
>   169d65a5774acc76ce3f3feeedcbae7405aa9b57 shows garbage ^[[H^[[J in
>   some of emacs screens. These screens do not handle ANSI escape
>   sequences. Therefore, clear screen is disabled on these screens.
> 
> v2:
> Remove check for TERM in fixup_after_attach().
> 
> Takashi Yano (1):
>   Cygwin: pty: Disable clear screen on new pty if TERM=dumb or emacs*.
> 
>  winsup/cygwin/fhandler_tty.cc | 19 ++-
>  winsup/cygwin/tty.cc  |  1 +
>  winsup/cygwin/tty.h   |  1 +
>  3 files changed, 16 insertions(+), 5 deletions(-)
> 
> -- 
> 2.21.0

Pushed.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer


signature.asc
Description: PGP signature


Re: [PATCH 0/1] Cygwin: pty: Fix select() with pseudo console support.

2019-09-05 Thread Corinna Vinschen
On Sep  5 13:22, Takashi Yano wrote:
> - select() did not work correctly when both read and except are
>   polled simultaneously for the same fd and the r/w pipe is switched
>   to pseudo console side. This patch fixes this isseu.
> 
> Takashi Yano (1):
>   Cygwin: pty: Fix select() with pseudo console support.
> 
>  winsup/cygwin/fhandler.h  |  15 +++
>  winsup/cygwin/fhandler_tty.cc |  13 ++-
>  winsup/cygwin/select.cc   | 192 --
>  winsup/cygwin/select.h|   2 +
>  4 files changed, 207 insertions(+), 15 deletions(-)
> 
> -- 
> 2.21.0

Pushed.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer


signature.asc
Description: PGP signature


Re: [PATCH 1/1] Cygwin: pty: Fix potential state mismatch regarding pseudo console.

2019-09-05 Thread Corinna Vinschen
On Sep  5 19:44, Takashi Yano wrote:
> - PTY with pseudo console support sitll has problem which potentially
>   cause state mismatch between state variable and real console state.
>   This patch fixes this issue.
> ---
>  winsup/cygwin/dtable.cc | 9 +++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
> index 4e9b6ed56..7b2e52005 100644
> --- a/winsup/cygwin/dtable.cc
> +++ b/winsup/cygwin/dtable.cc
> @@ -159,14 +159,19 @@ dtable::stdio_init ()
>   {
> bool attached = !!fhandler_console::get_console_process_id
>   (ptys->getHelperProcessId (), true);
> -   if (!attached)
> +   if (attached)
> + break;
> +   else
>   {
> /* Not attached to pseudo console in fork() or spawn()
>by some reason. This happens if the executable is
>a windows GUI binary, such as mintty. */
> FreeConsole ();
> if (AttachConsole (ptys->getHelperProcessId ()))
> - break;
> + {
> +   ptys->fixup_after_attach (false);
> +   break;
> + }
>   }
>   }
>   }
> -- 
> 2.21.0

Pushed.

FYI, Ken Brown is taking over from here as temporary co-maintainer for
Cygwin.  He'll build and upload Cygwin test releases during my absence.
Please don't hesitate to send more patches as required, Ken will review
and eventually push them.

Ken, if you like, please generate a new Cygwin test release now.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer


signature.asc
Description: PGP signature


[PATCH 0/1] Cygwin: pty: Make it sure to show up system error messages.

2019-09-05 Thread Takashi Yano
- Forcibly attach to pseudo console in advance so that the error
  messages by system_printf() is displayed to screen reliably.
  This is needed when stdout is redirected to another pty. In this
  case, process has two ptys opened. However, process can attach
  to only one console. So it is necessary to change console attached.

Takashi Yano (1):
  Cygwin: pty: Make it sure to show up system error messages.

 winsup/cygwin/fhandler_tty.cc | 55 +++
 1 file changed, 49 insertions(+), 6 deletions(-)

-- 
2.21.0



[PATCH 1/1] Cygwin: pty: Make it sure to show up system error messages.

2019-09-05 Thread Takashi Yano
- Forcibly attach to pseudo console in advance so that the error
  messages by system_printf() is displayed to screen reliably.
  This is needed when stdout is redirected to another pty. In this
  case, process has two ptys opened. However, process can attach
  to only one console. So it is necessary to change console attached.
---
 winsup/cygwin/fhandler_tty.cc | 55 +++
 1 file changed, 49 insertions(+), 6 deletions(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 78c9c9128..1a1ae1a5c 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -88,16 +88,59 @@ set_switch_to_pcon (void)
   }
 }
 
+static void
+force_attach_to_pcon (HANDLE h)
+{
+  bool attach_done = false;
+  for (int n = 0; n < 2; n ++)
+{
+  /* First time, attach to the pty whoes handle value is match.
+Second time, try to attach to any pty. */
+  cygheap_fdenum cfd (false);
+  while (cfd.next () >= 0)
+   if (cfd->get_major () == DEV_PTYS_MAJOR)
+ {
+   fhandler_base *fh = cfd;
+   fhandler_pty_slave *ptys = (fhandler_pty_slave *) fh;
+   if (n != 0
+   || h == ptys->get_handle ()
+   || h == ptys->get_output_handle ())
+ {
+   if (fhandler_console::get_console_process_id
+ (ptys->getHelperProcessId (), true))
+ attach_done = true;
+   else
+ {
+   FreeConsole ();
+   if (AttachConsole (ptys->getHelperProcessId ()))
+ {
+   pcon_attached_to = ptys->get_minor ();
+   attach_done = true;
+ }
+   else
+ pcon_attached_to = -1;
+ }
+   break;
+ }
+ }
+  if (attach_done)
+   break;
+}
+}
+
 void
 set_ishybrid_and_switch_to_pcon (HANDLE h)
 {
-  DWORD dummy;
-  if (!isHybrid
-  && GetFileType (h) == FILE_TYPE_CHAR
-  && GetConsoleMode (h, &dummy))
+  if (GetFileType (h) == FILE_TYPE_CHAR)
 {
-  isHybrid = true;
-  set_switch_to_pcon ();
+  force_attach_to_pcon (h);
+  DWORD dummy;
+  if (!isHybrid && (GetConsoleMode (h, &dummy)
+   || GetLastError () != ERROR_INVALID_HANDLE))
+   {
+ isHybrid = true;
+ set_switch_to_pcon ();
+   }
 }
 }
 
-- 
2.21.0



Re: [PATCH 0/1] Cygwin: pty: Make it sure to show up system error messages.

2019-09-05 Thread Ken Brown
On 9/5/2019 9:22 AM, Takashi Yano wrote:
> - Forcibly attach to pseudo console in advance so that the error
>messages by system_printf() is displayed to screen reliably.
>This is needed when stdout is redirected to another pty. In this
>case, process has two ptys opened. However, process can attach
>to only one console. So it is necessary to change console attached.
> 
> Takashi Yano (1):
>Cygwin: pty: Make it sure to show up system error messages.
> 
>   winsup/cygwin/fhandler_tty.cc | 55 +++
>   1 file changed, 49 insertions(+), 6 deletions(-)

Pushed, with a couple of minor typo fixes.

Thanks.

Ken

P.S. Please let me know whenever you think I should make a new test release. 
Also, I'll be mostly AFK for about a week starting on Saturday, so I probably 
won't be reviewing any patches during that time.