[PATCH 1/2] Cygwin: pty: Add a workaround for ^C handling.

Takashi Yano takashi.yano@nifty.ne.jp
Wed Sep 4 01:46:00 GMT 2019


- Pseudo console support introduced by commit
  169d65a5774acc76ce3f3feeedcbae7405aa9b57 sometimes cause random
  crash or freeze by pressing ^C while cygwin and non-cygwin
  processes are executed simultaneously in the same pty. This
  patch is a workaround for this issue.
---
 winsup/cygwin/fhandler_tty.cc | 5 +++++
 winsup/cygwin/spawn.cc        | 6 ++++++
 2 files changed, 11 insertions(+)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 240ee017c..283558985 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -2846,6 +2846,9 @@ fhandler_pty_slave::fixup_after_fork (HANDLE parent)
   // fork_fixup (parent, inuse, "inuse");
   // fhandler_pty_common::fixup_after_fork (parent);
   report_tty_counts (this, "inherited", "");
+  if (getPseudoConsole ())
+    myself->ctty = 0; /* Avoid setting init_console_handler() in fork.cc.
+			 This is a workaround for ^C handling problem. */
 }
 
 void
@@ -2882,6 +2885,8 @@ fhandler_pty_slave::fixup_after_exec ()
 	  FreeConsole ();
 	}
     }
+  if (getPseudoConsole () && myself->ctty == 0)
+    myself->ctty = get_ttyp ()->ntty; /* Restore ctty */
 
 #if USE_API_HOOK
   /* Hook Console API */
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 4bb28c47b..22dafbce3 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -634,6 +634,12 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
 	}
       if (ptys)
 	ptys->fixup_after_attach (!iscygwin ());
+      if (attach_to_pcon && !iscygwin ())
+	{
+	  myself->ctty = 0; /* Random freezes caused by ^C can be avoided
+			       with this. */
+	  init_console_handler (true);
+	}
 
     loop:
       /* When ruid != euid we create the new process under the current original
-- 
2.21.0



More information about the Cygwin-patches mailing list