From 6813f009ba2a95c9476e29fe356d2e3b46286efb Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Mon, 22 May 2006 04:50:54 +0000 Subject: [PATCH] * child_info.h (_CI_SAW_CTRL_C): New enum. (CURR_CHILD_INFO_MAGIC): Reset. (saw_ctrl_c): New function. (set_saw_ctrl_c): Ditto. * sigproc.cc (child_info::proc_retry): Return EXITCODE_OK if we get STATUS_CONTROL_C_EXIT and we actually saw a CTRL-C. * spawn.cc (dwExeced): Delete. (chExeced): New variable. (spawn_guts): Set chExeced; * exceptions.cc (dwExeced): Delete declaration. (chExeced): Declare. (ctrl_c_handler): Detect if we're an exec stub process and set a flag, if so. * fhandler_tty.cc (fhandler_tty_common::__release_output_mutex): Add extra DEBUGGING test. * pinfo.cc: Fix comment. --- winsup/cygwin/ChangeLog | 21 +++++++++++++++++++++ winsup/cygwin/child_info.h | 10 +++++++--- winsup/cygwin/exceptions.cc | 12 +++++++----- winsup/cygwin/fhandler_tty.cc | 7 +++++++ winsup/cygwin/pinfo.cc | 4 ++-- winsup/cygwin/sigproc.cc | 3 +++ winsup/cygwin/spawn.cc | 5 +++-- 7 files changed, 50 insertions(+), 12 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index d1481ee87..9dd8d341c 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,24 @@ +2006-05-21 Christopher Faylor + + * child_info.h (_CI_SAW_CTRL_C): New enum. + (CURR_CHILD_INFO_MAGIC): Reset. + (saw_ctrl_c): New function. + (set_saw_ctrl_c): Ditto. + * sigproc.cc (child_info::proc_retry): Return EXITCODE_OK if we get + STATUS_CONTROL_C_EXIT and we actually saw a CTRL-C. + * spawn.cc (dwExeced): Delete. + (chExeced): New variable. + (spawn_guts): Set chExeced; + * exceptions.cc (dwExeced): Delete declaration. + (chExeced): Declare. + (ctrl_c_handler): Detect if we're an exec stub process and set a flag, + if so. + + * fhandler_tty.cc (fhandler_tty_common::__release_output_mutex): Add + extra DEBUGGING test. + + * pinfo.cc: Fix comment. + 2006-05-21 Christopher Faylor * fhandle.h (fhandler_pipe::create_guard): Revert change which diff --git a/winsup/cygwin/child_info.h b/winsup/cygwin/child_info.h index 4d0ea0195..7f1a88c17 100644 --- a/winsup/cygwin/child_info.h +++ b/winsup/cygwin/child_info.h @@ -20,8 +20,10 @@ enum child_info_types enum child_status { - _CI_STRACED = 0x01, - _CI_ISCYGWIN = 0x02 + _CI_STRACED = 0x01, + _CI_ISCYGWIN = 0x02, + _CI_SAW_CTRL_C = 0x04 + }; #define OPROC_MAGIC_MASK 0xff00ff00 @@ -36,7 +38,7 @@ enum child_status #define EXEC_MAGIC_SIZE sizeof(child_info) /* Change this value if you get a message indicating that it is out-of-sync. */ -#define CURR_CHILD_INFO_MAGIC 0x110015eaU +#define CURR_CHILD_INFO_MAGIC 0x704d1f7eU /* NOTE: Do not make gratuitous changes to the names or organization of the below class. The layout is checksummed to determine compatibility between @@ -68,6 +70,8 @@ public: DWORD proc_retry (HANDLE) __attribute__ ((regparm (2))); bool isstraced () const {return !!(flag & _CI_STRACED);} bool iscygwin () const {return !!(flag & _CI_ISCYGWIN);} + bool saw_ctrl_c () const {return !!(flag & _CI_SAW_CTRL_C);} + void set_saw_ctrl_c () {flag |= _CI_SAW_CTRL_C;} }; class mount_info; diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index b18d82a82..fcc13d100 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -31,6 +31,7 @@ details. */ #include "fhandler.h" #include "dtable.h" #include "cygheap.h" +#include "child_info.h" #define CALL_HANDLER_RETRY 20 @@ -40,7 +41,7 @@ extern "C" { extern void sigdelayed (); }; -extern NO_COPY DWORD dwExeced; +extern child_info_spawn *chExeced; int NO_COPY sigExeced; static BOOL WINAPI ctrl_c_handler (DWORD); @@ -944,10 +945,11 @@ ctrl_c_handler (DWORD type) } } - /* If we are a stub and the new process has a pinfo structure, let it - handle this signal. */ - if (dwExeced && pinfo (dwExeced)) - return TRUE; + if (chExeced) + { + chExeced->set_saw_ctrl_c (); + return TRUE; + } /* We're only the process group leader when we have a valid pinfo structure. If we don't have one, then the parent "stub" will handle the signal. */ diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 853972840..39691c629 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -148,6 +148,13 @@ fhandler_tty_common::__release_output_mutex (const char *fn, int ln) ostack[osi].ln = -ln; #endif } +#ifdef DEBUGGING + else if (osi > 0) + { + system_printf ("couldn't release output mutex but we seem to own it, %E"); + try_to_debug (); + } +#endif } /* Process tty input. */ diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index 8aeaa64bb..504c1c9f2 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -41,8 +41,8 @@ pinfo NO_COPY myself ((_pinfo *)&pinfo_dummy); // Avoid myself != NULL checks bool is_toplevel_proc; -/* Initialize the process table. - This is done once when the dll is first loaded. */ +/* Setup the pinfo structure for this process. There may already be a + _pinfo for this "pid" if h != NULL. */ void __stdcall set_myself (HANDLE h) diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 9eb918dc1..5de0762e8 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -910,6 +910,9 @@ child_info::proc_retry (HANDLE h) sigproc_printf ("STILL_ACTIVE? How'd we get here?"); break; case STATUS_CONTROL_C_EXIT: + if (saw_ctrl_c ()) + return EXITCODE_OK; + /* fall through intentionally */ case STATUS_DLL_INIT_FAILED: case STATUS_DLL_INIT_FAILED_LOGOFF: case EXITCODE_RETRY: diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 41f40543e..9f04b3074 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -52,7 +52,7 @@ static suffix_info dll_suffixes[] = }; HANDLE hExeced; -DWORD dwExeced; +child_info_spawn *chExeced; /* Add .exe to PROG if not already present and see if that exists. If not, return PROG (converted from posix to win32 rules if necessary). @@ -583,7 +583,8 @@ loop: pid_t pid; if (mode == _P_OVERLAY) { - myself->dwProcessId = dwExeced = pi.dwProcessId; + chExeced = &ch; /* FIXME: there's a race here if a user sneaks in CTRL-C */ + myself->dwProcessId = pi.dwProcessId; strace.execing = 1; myself.hProcess = hExeced = pi.hProcess; strcpy (myself->progname, real_path); // FIXME: race?