From 936e4018b6fd1ad21ac528cf567fa81a46b054b0 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Fri, 23 Sep 2005 03:35:41 +0000 Subject: * cygheap.cc (cygheap_fixup_in_child): It's not just for exec. * cygtls.h (struct _cygtls::thread_handle): New field. * dcrt0.cc (exit_lock): Remove declaration. * winsup.h (exit_lock): Add declaration. * exceptions.cc (sigpacket::process): Properly return after signal_exit. * pinfo.cc (pinfo::exit): Only exit the process if _my_tls.thread_handle has not been filled out -- which should be an impossible event. * sigproc.cc (sigproc_terminate): Fillout _my_tls.thread_handle to provide something for wait_sig to wait for. Use the siginfo_t version of sig_send and fill out the tls argument with _my_tls. (wait_sig): Wait for the thread specified in pack.tls or (for now) complain bitterly if it doesn't exit. --- winsup/cygwin/sigproc.cc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'winsup/cygwin/sigproc.cc') diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index b9c66f376..8d84551eb 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -497,7 +497,15 @@ sigproc_terminate (exit_states es) else { sigproc_printf ("entering"); - sig_send (myself_nowait, __SIGEXIT); + siginfo_t si; + memset (&si, 0, sizeof (si)); + si.si_signo = __SIGEXIT; + if (&_my_tls == _main_tls) + _my_tls.thread_handle = hMainThread; + else + DuplicateHandle (hMainProc, GetCurrentThread (), hMainProc, &_my_tls.thread_handle, 0, + FALSE, DUPLICATE_SAME_ACCESS); + sig_send (myself_nowait, si, &_my_tls); proc_terminate (); // clean up process stuff } } @@ -1005,10 +1013,11 @@ wait_sig (VOID *self) debug_printf ("entering ReadFile loop, readsig %p, myself->sendsig %p", readsig, myself->sendsig); + sigpacket pack; for (;;) { DWORD nb; - sigpacket pack; + pack.tls = NULL; if (!ReadFile (readsig, &pack, sizeof (pack), &nb, NULL)) break; @@ -1114,9 +1123,13 @@ wait_sig (VOID *self) break; } - HANDLE h = hMainThread; - my_sendsig = hMainThread = NULL; - DWORD res = !h ? WAIT_OBJECT_0 : WaitForSingleObject (h, INFINITE); + my_sendsig = NULL; + if (!pack.tls) + api_fatal ("no exit packet received"); + if (!pack.tls->thread_handle) + api_fatal ("no thread handle set on exit"); + HANDLE h = pack.tls->thread_handle; + DWORD res = WaitForSingleObject (h, INFINITE); DWORD exitcode = 1; -- cgit v1.2.3