public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: pty: Use pinfo() rather than kill() with signal 0.
Date: Thu, 06 Feb 2020 19:02:00 -0000	[thread overview]
Message-ID: <20200206190209.82005.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=3a71c46380f2cad6a9cb9d182c117cb624214553

commit 3a71c46380f2cad6a9cb9d182c117cb624214553
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Thu Feb 6 19:48:17 2020 +0900

    Cygwin: pty: Use pinfo() rather than kill() with signal 0.
    
    - 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().

Diff:
---
 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 9270c83..82527ec 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 1dd57b3..181bed5 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;


                 reply	other threads:[~2020-02-06 19:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200206190209.82005.qmail@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /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).