www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/01/08/11:20:37

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Tue, 8 Jan 2002 11:19:51 -0500
From: Christopher Faylor <cgf AT redhat DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: bash/cmd CTRL-C problem...
Message-ID: <20020108161950.GC22944@redhat.com>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <000f01c19766$549cb8e0$0200a8c0 AT lifelesswks> <017b01c1976a$21451e70$c51811ac AT brokat DOT de> <007b01c1977d$6093f520$0200a8c0 AT lifelesswks> <20020107165105 DOT GB4652 AT redhat DOT com> <037a01c197cf$1d0a4000$0200a8c0 AT lifelesswks> <20020107234555 DOT GA11984 AT redhat DOT com> <03ca01c197d9$8a16c510$0200a8c0 AT lifelesswks> <20020108002140 DOT GA12820 AT redhat DOT com> <03f001c197dd$7a9bec10$0200a8c0 AT lifelesswks> <013201c19812$2125e750$0200a8c0 AT lifelesswks>
Mime-Version: 1.0
In-Reply-To: <013201c19812$2125e750$0200a8c0@lifelesswks>
User-Agent: Mutt/1.3.23.1i

On Tue, Jan 08, 2002 at 06:00:16PM +1100, Robert Collins wrote:
>FWIW this patch (Chris where should I put the in_stub declaration)

There is already an indicator that an execed process is running --
hExeced, so I don't think you need the 'in_stub' thing.

However, it seems to me that this solution is racy.  If a person types
CTRL-C during process startup, it's possible that a cygwin process will
never see a true cygwin signal.  Hmm.  I guess this race is already
in signal_exit, in fact.  I have to fix that.

Regardless, it is not always the correct behavior for CTRL-C just do
the "default thing".  If the execed process is supposed to be ignoring
SIGINT then it isn't right for the process to exit.

Also, your change seems to make no distinction between a spawned and
execed process.  It looks like if the user had called spawn, a CTRL-C
would just cause the parent process to die.

cgf

>====
>Index: exceptions.cc
>===================================================================
>RCS file: /cvs/src/src/winsup/cygwin/exceptions.cc,v
>retrieving revision 1.103
>diff -u -p -r1.103 exceptions.cc
>--- exceptions.cc       2002/01/05 22:25:34     1.103
>+++ exceptions.cc       2002/01/08 06:54:23
>@@ -890,11 +890,14 @@ setup_handler (int sig, void *handler, s
> #error "Need to supply machine dependent setup_handler"
> #endif
>
>+// Yeah, well. Where to put this?
>+bool in_stub = false;
>+
> /* CGF Keyboard interrupt handler.  */
> static BOOL WINAPI
> ctrl_c_handler (DWORD type)
> {
>-  if (type == CTRL_LOGOFF_EVENT)
>+  if (type == CTRL_LOGOFF_EVENT || (type == CTRL_C_EVENT && in_stub ==
>true))
>     return TRUE;
>
>   /* Return FALSE to prevent an "End task" dialog box from appearing
>Index: spawn.cc
>===================================================================
>RCS file: /cvs/src/src/winsup/cygwin/spawn.cc,v
>retrieving revision 1.94
>diff -u -p -r1.94 spawn.cc
>--- spawn.cc    2001/11/05 06:09:08     1.94
>+++ spawn.cc    2002/01/08 06:54:25
>@@ -314,6 +314,9 @@ av::unshift (const char *what, int conv)
>   return 1;
> }
>
>+// From exceptions.cc
>+extern bool in_stub; // indicate when we are wrapping a non-cygwin
>program
>+
> static int __stdcall
> spawn_guts (HANDLE hToken, const char * prog_arg, const char *const
>*argv,
>            const char *const envp[], int mode)
>@@ -804,8 +807,10 @@ spawn_guts (HANDLE hToken, const char *
>   MALLOC_CHECK;
>   if (mode == _P_OVERLAY)
>     {
>+      in_stub = true; // don't close on CTRL C.
>       int nwait = 3;
>       HANDLE waitbuf[3] = {pi.hProcess, signal_arrived, spr};
>+      // If spr is not triggered, it's not a cygwin process ?
>       for (int i = 0; i < 100; i++)
>        {
>          switch (WaitForMultipleObjects (nwait, waitbuf, FALSE,
>INFINITE))
>@@ -823,6 +828,7 @@ spawn_guts (HANDLE hToken, const char *
>              reset_signal_arrived ();
>              continue;
>            case WAIT_OBJECT_0 + 2:
>+             // SPR
>              if (myself->ppid_handle)
>                res |= EXIT_REPARENTING;
>              if (!my_parent_is_alive ())
>@@ -847,6 +853,7 @@ spawn_guts (HANDLE hToken, const char *
>            }
>          break;
>        }
>+
>
>       ForceCloseHandle (spr);
>
>@@ -874,6 +881,8 @@ spawn_guts (HANDLE hToken, const char *
>              system_printf ("old hProcess %p, hProcess %p", oldh,
>myself->hProcess);
>            }
>        }
>+      in_stub = false; // We're safely reparented now, or a cygwin
>wrapped win32
>+      // program has terminated.
>
>     }
>====
>
>means that I get this output from the test programs:
>=============
>Administrator AT LIFELESSWKS ~/t
>$ ./signals.exe
>
>>>> signals: Waiting now...
>>>>>>> myclass CPP: Installing atexit handler...
>
>>>>>>> myclass CPP: Installing signal handler...
>>>>>>> myclass CPP: Falling asleep...
>............................................................
>>>> signals: Signal SIGINT=2 received
>......................................
>>>> signals: Finished waiting now...
>
>>>> signals: Forwarding CTRL_BREAK_EVENT to the child process...
>..
>>>>>>> myclass CPP: SIGBREAK caught...
>>>>>>> myclass CPP: Process terminating...
>
>
>=================
>
>So it looks like it solves it. I've noticed no side effects either.
>
>Rob
>
>
>--
>Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>Bug reporting:         http://cygwin.com/bugs.html
>Documentation:         http://cygwin.com/docs.html
>FAQ:                   http://cygwin.com/faq/

-- 
cgf AT redhat DOT com                        Red Hat, Inc.
http://sources.redhat.com/            http://www.redhat.com/

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019