This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: bash/cmd CTRL-C problem...


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@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@redhat.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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]