From 1d04c4c6c36f307f79a5617bc62e1a766ce01355 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sat, 26 Nov 2011 02:35:49 +0000 Subject: [PATCH] * exceptions.cc (sigpacket::process): Move signal_exit processing into... (_cygtls::signal_exit): ...here. Close my_readsig and comment on why. * pinfo.cc (pinfo::exit): Move sigproc_terminate earlier. Set exiting flag in lock_process. * sigproc.cc (my_readsig): Make global. * sync.cc (muto::exiting_thread): Delete. (muto::acquire): Delete #if 0'ed code. * sync.h (muto::exiting_thread): Delete. (set_exiting_thread): Ditto. (lock_process::lock_process): Don't worry about setting the exiting thread since it had no meaning. --- winsup/cygwin/ChangeLog | 14 ++++++++++++++ winsup/cygwin/exceptions.cc | 25 ++++++++++++++----------- winsup/cygwin/pinfo.cc | 4 ++-- winsup/cygwin/sigproc.cc | 2 +- winsup/cygwin/sync.cc | 5 ----- winsup/cygwin/sync.h | 7 +------ 6 files changed, 32 insertions(+), 25 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 32066c4ec..a3f1e94d2 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,17 @@ +2011-11-25 Christopher Faylor + + * exceptions.cc (sigpacket::process): Move additional processing into... + (_cygtls::signal_exit): ...here. Close my_readsig and comment on why. + * pinfo.cc (pinfo::exit): Move sigproc_terminate earlier. Set exiting + flag in lock_process. + * sigproc.cc (my_readsig): Make global. + * sync.cc (muto::exiting_thread): Delete. + (muto::acquire): Delete #if 0'ed code. + * sync.h (muto::exiting_thread): Delete. + (set_exiting_thread): Ditto. + (lock_process::lock_process): Don't worry about setting the exiting + thread since it had no meaning. + 2011-11-24 Christopher Faylor * cygthread.cc (cygthread::name): Default name to "main" if we are early diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 98707e22a..b84a9fb35 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -1307,17 +1307,6 @@ thread_specific: goto done; exit_sig: - if (si.si_signo == SIGQUIT || si.si_signo == SIGABRT) - { - CONTEXT c; - c.ContextFlags = CONTEXT_FULL; - GetThreadContext (hMainThread, &c); - use_tls->copy_context (&c); - if (cygheap->rlim_core > 0UL) - si.si_signo |= 0x80; - } - SetEvent (signal_arrived); // To avoid a potential deadlock with proc_lock - sigproc_printf ("signal %d, about to call do_exit", si.si_signo); use_tls->signal_exit (si.si_signo); /* never returns */ } @@ -1327,6 +1316,20 @@ exit_sig: void _cygtls::signal_exit (int rc) { + extern HANDLE my_readsig; + ForceCloseHandle (my_readsig); /* Disallow further signal sends */ + SetEvent (signal_arrived); /* Avoid potential deadlock with proc_lock */ + + if (rc == SIGQUIT || rc == SIGABRT) + { + CONTEXT c; + c.ContextFlags = CONTEXT_FULL; + GetThreadContext (hMainThread, &c); + copy_context (&c); + if (cygheap->rlim_core > 0UL) + rc |= 0x80; + } + if (have_execed) { sigproc_printf ("terminating captive process"); diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index 48a5a99b2..d3e68bf32 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -181,7 +181,8 @@ void pinfo::exit (DWORD n) { minimal_printf ("winpid %d, exit %d", GetCurrentProcessId (), n); - lock_process until_exit (); + sigproc_terminate (ES_FINAL); + lock_process until_exit (true); cygthread::terminate (); if (n != EXITCODE_NOSET) @@ -192,7 +193,6 @@ pinfo::exit (DWORD n) maybe_set_exit_code_from_windows (); } - sigproc_terminate (ES_FINAL); if (myself->ctty > 0 && !iscons_dev (myself->ctty)) { lock_ttys here; diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index d3737e35c..e834f0bc6 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -64,7 +64,7 @@ Static muto sync_proc_subproc; // Control access to subproc stuff _cygtls NO_COPY *_sig_tls; Static HANDLE my_sendsig; -Static HANDLE my_readsig; +HANDLE NO_COPY my_readsig; /* Function declarations */ static int __stdcall checkstate (waitq *) __attribute__ ((regparm (1))); diff --git a/winsup/cygwin/sync.cc b/winsup/cygwin/sync.cc index 58b854912..0731fd18f 100644 --- a/winsup/cygwin/sync.cc +++ b/winsup/cygwin/sync.cc @@ -20,7 +20,6 @@ details. */ #undef WaitForSingleObject -DWORD NO_COPY muto::exiting_thread; muto NO_COPY lock_process::locker; void @@ -76,10 +75,6 @@ int muto::acquire (DWORD ms) { void *this_tls = &_my_tls; -#if 0 - if (exiting_thread) - return this_tid == exiting_thread; -#endif if (tls != this_tls) { diff --git a/winsup/cygwin/sync.h b/winsup/cygwin/sync.h index 5d66b97af..2215599c8 100644 --- a/winsup/cygwin/sync.h +++ b/winsup/cygwin/sync.h @@ -17,7 +17,6 @@ class muto public: const char *name; private: - static DWORD exiting_thread; LONG sync; /* Used to serialize access to this class. */ LONG waiters; /* Number of threads waiting for lock. */ HANDLE bruteforce; /* event handle used to control waiting for lock. */ @@ -39,7 +38,6 @@ public: void upforgrabs () {tls = this;} // just set to an invalid address void grab () __attribute__ ((regparm (1))); operator int () const {return !!name;} - static void set_exiting_thread () {exiting_thread = GetCurrentThreadId ();} }; class lock_process @@ -54,10 +52,7 @@ public: locker.acquire (); skip_unlock = exiting; if (exiting && exit_state < ES_PROCESS_LOCKED) - { - exit_state = ES_PROCESS_LOCKED; - muto::set_exiting_thread (); - } + exit_state = ES_PROCESS_LOCKED; } ~lock_process () {