[PATCH] Cygwin: pty: Use pinfo() rather than kill() with signal 0.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Cygwin: pty: Use pinfo() rather than kill() with signal 0.

Takashi Yano
- PTY code has a problem that tcsh is terminated if the following
  command is executed.
    true; chcp &
  This seems to be caused by invalid pointer access which occurs
  when the process exits during the kill() code is execuetd. This
  patch avoids the issue by not using kill().
---
 winsup/cygwin/fhandler.h      |  2 +-
 winsup/cygwin/fhandler_tty.cc | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 9270c837c..82527eca3 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -2211,7 +2211,7 @@ class fhandler_pty_slave: public fhandler_pty_common
   {
     if (!mask && get_ttyp ()->pcon_pid &&
  get_ttyp ()->pcon_pid != myself->pid &&
- kill (get_ttyp ()->pcon_pid, 0) == 0)
+ !!pinfo (get_ttyp ()->pcon_pid))
       return;
     get_ttyp ()->mask_switch_to_pcon_in = mask;
   }
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 1dd57b369..181bed5a9 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -1103,7 +1103,7 @@ fhandler_pty_slave::set_switch_to_pcon (int fd_set)
 skip_console_setting:
       restore_reattach_pcon ();
       if (get_ttyp ()->pcon_pid == 0 ||
-  kill (get_ttyp ()->pcon_pid, 0) != 0)
+  !pinfo (get_ttyp ()->pcon_pid))
  get_ttyp ()->pcon_pid = myself->pid;
       get_ttyp ()->switch_to_pcon_in = true;
     }
@@ -1111,7 +1111,7 @@ skip_console_setting:
     {
       wait_pcon_fwd ();
       if (get_ttyp ()->pcon_pid == 0 ||
-  kill (get_ttyp ()->pcon_pid, 0) != 0)
+  !pinfo (get_ttyp ()->pcon_pid))
  get_ttyp ()->pcon_pid = myself->pid;
       get_ttyp ()->switch_to_pcon_out = true;
     }
@@ -1124,7 +1124,7 @@ fhandler_pty_slave::reset_switch_to_pcon (void)
     this->set_switch_to_pcon (fd);
   if (get_ttyp ()->pcon_pid &&
       get_ttyp ()->pcon_pid != myself->pid &&
-      kill (get_ttyp ()->pcon_pid, 0) == 0)
+      !!pinfo (get_ttyp ()->pcon_pid))
     /* There is a process which is grabbing pseudo console. */
     return;
   if (isHybrid)
@@ -2728,7 +2728,7 @@ fhandler_pty_slave::fixup_after_attach (bool native_maybe, int fd_set)
  ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT;
       SetConsoleMode (get_handle (), mode);
       if (get_ttyp ()->pcon_pid == 0 ||
-  kill (get_ttyp ()->pcon_pid, 0) != 0)
+  !pinfo (get_ttyp ()->pcon_pid))
  get_ttyp ()->pcon_pid = myself->pid;
       get_ttyp ()->switch_to_pcon_in = true;
     }
@@ -2739,7 +2739,7 @@ fhandler_pty_slave::fixup_after_attach (bool native_maybe, int fd_set)
       if (!get_ttyp ()->switch_to_pcon_out)
  wait_pcon_fwd ();
       if (get_ttyp ()->pcon_pid == 0 ||
-  kill (get_ttyp ()->pcon_pid, 0) != 0)
+  !pinfo (get_ttyp ()->pcon_pid))
  get_ttyp ()->pcon_pid = myself->pid;
       get_ttyp ()->switch_to_pcon_out = true;
 
--
2.21.0

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Cygwin: pty: Use pinfo() rather than kill() with signal 0.

Corinna Vinschen-2
On Feb  6 19:48, Takashi Yano wrote:
> - PTY code has a problem that tcsh is terminated if the following
>   command is executed.
>     true; chcp &
>   This seems to be caused by invalid pointer access which occurs
>   when the process exits during the kill() code is execuetd. This
>   patch avoids the issue by not using kill().

Pushed.

I'm inclined to release 3.1.3 next week.  Is that ok with you or
do you anticipate more patches which should go into 3.1.3?


Thanks,
Corinna

--
Corinna Vinschen
Cygwin Maintainer

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Cygwin: pty: Use pinfo() rather than kill() with signal 0.

Takashi Yano
On Thu, 6 Feb 2020 20:03:30 +0100
Corinna Vinschen wrote:
> I'm inclined to release 3.1.3 next week.  Is that ok with you or
> do you anticipate more patches which should go into 3.1.3?

Currently, I have two patches which are under test. I would be
happy if these could be included in 3.1.3. I am planning to
divide one of them into several patches. I will submit these
patches in a few days.

--
Takashi Yano <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Cygwin: pty: Use pinfo() rather than kill() with signal 0.

Takashi Yano
On Sat, 8 Feb 2020 23:53:11 +0900
Takashi Yano wrote:
> On Thu, 6 Feb 2020 20:03:30 +0100
> Corinna Vinschen wrote:
> > I'm inclined to release 3.1.3 next week.  Is that ok with you or
> > do you anticipate more patches which should go into 3.1.3?
>
> Currently, I have two patches which are under test. I would be
> happy if these could be included in 3.1.3. I am planning to
> divide one of them into several patches. I will submit these
> patches in a few days.

Please apply these patches in the following order.

[PATCH 1/4] Cygwin: pty: Define mask_switch_to_pcon_in() in fhandler_tty.cc.
[PATCH 2/4] Cygwin: pty: Avoid screen distortion on slave read.
[PATCH 3/4] Cygwin: pty: Remove debug codes and organize related codes.
[PATCH 4/4] Cygwin: pty: Add missing member initialization for struct pipe_reply.
[PATCH] Cygwin: pty: Inherit typeahead data between two input pipes.
[PATCH] Cygwin: pty: Fix state mismatch caused in mintty.

--
Takashi Yano <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Cygwin: pty: Use pinfo() rather than kill() with signal 0.

Takashi Yano
Hi Corinna,

On Mon, 10 Feb 2020 00:06:03 +0900
Takashi Yano wrote:

> On Sat, 8 Feb 2020 23:53:11 +0900
> Takashi Yano wrote:
> > On Thu, 6 Feb 2020 20:03:30 +0100
> > Corinna Vinschen wrote:
> > > I'm inclined to release 3.1.3 next week.  Is that ok with you or
> > > do you anticipate more patches which should go into 3.1.3?
> >
> > Currently, I have two patches which are under test. I would be
> > happy if these could be included in 3.1.3. I am planning to
> > divide one of them into several patches. I will submit these
> > patches in a few days.
>
> Please apply these patches in the following order.
>
> [PATCH 1/4] Cygwin: pty: Define mask_switch_to_pcon_in() in fhandler_tty.cc.
> [PATCH 2/4] Cygwin: pty: Avoid screen distortion on slave read.
> [PATCH 3/4] Cygwin: pty: Remove debug codes and organize related codes.
> [PATCH 4/4] Cygwin: pty: Add missing member initialization for struct pipe_reply.
> [PATCH] Cygwin: pty: Inherit typeahead data between two input pipes.
> [PATCH] Cygwin: pty: Fix state mismatch caused in mintty.

I am sorry, but I have submitted one more trivial patch.

--
Takashi Yano <[hidden email]>