Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2000-10-15 05:37:07 +0400
committerChristopher Faylor <me@cgf.cx>2000-10-15 05:37:07 +0400
commit1dc16fc74bb91136d75b656f3a4aaefa87af9f20 (patch)
treeb0b9173fa268afc99bba53c5814736c5a8b2cca1 /winsup/cygwin/sigproc.cc
parentfdc614360f491de1b76e766b96251895391693b2 (diff)
* exceptions.cc (set_console_handler): Don't allocate
console_handler_thread_waiter. It is obsolete. (ctrl_c_handler): Don't use console_handler_thread_waiter. * path.cc (hash_path_name): Fix handling of relative names. Make case insensitive. * path.h (suffix_info): Use initializers. * pinfo.h (_pinfo): Avoid initializers for null case. * resource.cc (fill_rusage): Zero rest of rusage structure. * security.cc (set_process_privileges): Don't reopen parent process. Just use hMainProc. * signal.cc (signal): Track when a signal handler has been used. (sigaction): Ditto. * sigproc.cc (pchildren): Use default initializer. (zombies): Ditto. (sigproc_terminate): Avoid closing handles that will be closed on exit anyway. (wait_sig): Send signal to "parent" on EXECing, not FORKing. (wait_subproc): Send SIGCHLD here rather than in proc_wait to avoid potential muto conflicts. * sigproc.h (sigthread): Don't initialize to zero. It's the default. * spawn.cc (spawn_guts): Fill in resources from exec parent prior to termination. * sync.h (muto): Don't initialize to zero. * syscalls.cc (close_all_files): Use one lock around entire loop and call fhandler close/release stuff directly. (_read): Don't use ready_for_read if there are not signal handlers active. * dcrt0.cc (dll_crt0_1): Fix display of "title". (do_exit): Use pinfo exit method to exit. (__api_fatal): Ditto. * exceptions.cc (signal_exit): Ditto. * fork.cc (fork_child): Remove debugging stuff. Use pinfo_fixup_after fork in place of exec_fixup_after_fork. * pinfo.cc (pinfo_fixup_after_fork): New method. (pinfo_fixup_in_spawned_child): Ditto. (_pinfo::exit): New method. (_pinfo::init): Remove recursion. Detect pathological case where pinfo structure already exists for new pid. * pinfo.h (_pinfo): Reorganize slightly. Add new method and new function declarations. * sigproc.cc (proc_exists): Previous simplification was a little to simple. Try harder to detect if a process exists. (proc_terminate): Use PID_EXITED setting to determine if process is still around. (WFSO): Remove debugging statement. (WFMO): Ditto. * spawn.cc (exec_fixup_after_fork): Eliminate. (spawn_guts): Always set old_title to NULL. Is it really needed? Move hexec_proc to pinfo.cc. Call pinfo_fixup_in_spawned_child to eliminate handle link after a spawn. * include/sys/cygwin.h: Remove PID_NOT_IN_USE. Add PID_EXITED.
Diffstat (limited to 'winsup/cygwin/sigproc.cc')
-rw-r--r--winsup/cygwin/sigproc.cc63
1 files changed, 25 insertions, 38 deletions
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 675feb4f3..1253b23eb 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -97,8 +97,8 @@ Static HANDLE wait_sig_inited = NULL; // Control synchronization of
*/
Static HANDLE events[PSIZE + 1] = {0}; // All my children's handles++
#define hchildren (events + 1) // Where the children handles begin
-Static pinfo pchildren[PSIZE] = {pinfo ()};// All my children info
-Static pinfo zombies[PSIZE] = {pinfo ()}; // All my deceased children info
+Static pinfo pchildren[PSIZE]; // All my children info
+Static pinfo zombies[PSIZE]; // All my deceased children info
Static int nchildren = 0; // Number of active children
Static int nzombies = 0; // Number of deceased children
@@ -195,18 +195,12 @@ pid_exists (pid_t pid)
return proc_exists (p);
}
-/* Test to determine if a process really exists and is processing
- * signals.
+/* Test to determine if a process really exists and is processing signals.
*/
BOOL __stdcall
proc_exists (_pinfo *p)
{
- HANDLE h;
-
- if (p == NULL)
- return FALSE;
- else
- return TRUE;
+ return p && !(p->process_state & (PID_INITIALIZING | PID_EXITED));
}
/* Return 1 if this is one of our children, zero otherwise.
@@ -266,7 +260,7 @@ proc_subproc (DWORD what, DWORD val)
hchildren[nchildren] = vchild->hProcess;
ProtectHandle1 (vchild->hProcess, childhProc);
if (!DuplicateHandle (hMainProc, vchild->hProcess, hMainProc, &vchild->pid_handle,
- 0, 0, DUPLICATE_SAME_ACCESS))
+ 0, 0, DUPLICATE_SAME_ACCESS))
system_printf ("Couldn't duplicate child handle for pid %d, %E", vchild->pid);
ProtectHandle1 (vchild->pid_handle, pid_handle);
sigproc_printf ("added pid %d to wait list, slot %d, winpid %p, handle %p",
@@ -301,11 +295,6 @@ proc_subproc (DWORD what, DWORD val)
zombies[nzombies] = pchildren[val]; // Add to zombie array
zombies[nzombies++]->process_state = PID_ZOMBIE;// Walking dead
remove_child (val); // Remove from children array
- if (!proc_loop_wait) // Don't bother if wait_subproc is
- break; // exiting
-
- /* Send a SIGCHLD to myself. */
- rc = sig_send (myself_nowait, SIGCHLD); // Send a SIGCHLD
break;
/* A child is in the stopped state. Scan wait() queue to see if anyone
@@ -445,15 +434,13 @@ proc_terminate (void)
ForceCloseHandle1 (zombies[i]->hProcess, childhProc);
ForceCloseHandle1 (zombies[i]->pid_handle, pid_handle);
}
- zombies[i]->process_state = PID_NOT_IN_USE; /* CGF FIXME - still needed? */
+ zombies[i]->process_state = PID_EXITED; /* CGF FIXME - still needed? */
zombies[i].release(); // FIXME: this breaks older gccs for some reason
}
/* Disassociate my subprocesses */
for (i = 0; i < nchildren; i++)
{
- if (pchildren[i]->process_state == PID_NOT_IN_USE)
- continue; // Should never happen
if (!pchildren[i]->hProcess)
sigproc_printf ("%d(%d) hProcess cleared already?", pchildren[i]->pid,
pchildren[i]->dwProcessId);
@@ -596,10 +583,10 @@ sigproc_terminate (void)
ForceCloseHandle (sigcomplete_main);
for (int i = 0; i < 20; i++)
(void) ReleaseSemaphore (sigcomplete_nonmain, 1, NULL);
- ForceCloseHandle (sigcomplete_nonmain);
- ForceCloseHandle (sigcatch_main);
- ForceCloseHandle (sigcatch_nonmain);
- ForceCloseHandle (sigcatch_nosync);
+ // ForceCloseHandle (sigcomplete_nonmain);
+ // ForceCloseHandle (sigcatch_main);
+ // ForceCloseHandle (sigcatch_nonmain);
+ // ForceCloseHandle (sigcatch_nosync);
}
proc_terminate (); // Terminate process handling thread
@@ -610,19 +597,19 @@ sigproc_terminate (void)
sigproc_printf ("entering");
sig_loop_wait = 0; // Tell wait_sig to exit when it is
// finished with anything it is doing
- sig_dispatch_pending (TRUE); // wake up and die
+ // sig_dispatch_pending (TRUE); // wake up and die
+ /* In case of a sigsuspend */
+ SetEvent (signal_arrived);
/* If !hwait_sig, then the process probably hasn't even finished
* its initialization phase.
*/
- if (hwait_sig)
+ if (0 && hwait_sig)
{
if (GetCurrentThreadId () != sigtid)
WaitForSingleObject (h, 10000);
ForceCloseHandle1 (h, hwait_sig);
- /* In case of a sigsuspend */
- SetEvent (signal_arrived);
if (GetCurrentThreadId () != sigtid)
{
@@ -636,9 +623,11 @@ sigproc_terminate (void)
sigproc_printf ("done");
}
+#if 0
/* Set this so that subsequent tests will succeed. */
if (!myself->dwProcessId)
myself->dwProcessId = GetCurrentProcessId ();
+#endif
return;
}
@@ -1128,7 +1117,7 @@ wait_sig (VOID *)
* Signalling subproc_ready indicates that we are a cygwin process.
*/
if (child_proc_info &&
- (child_proc_info->type == PROC_FORK || child_proc_info->type == PROC_SPAWN))
+ (child_proc_info->type == PROC_EXEC || child_proc_info->type == PROC_SPAWN))
{
debug_printf ("subproc_ready %p", child_proc_info->subproc_ready);
if (!SetEvent (child_proc_info->subproc_ready))
@@ -1144,13 +1133,6 @@ wait_sig (VOID *)
SetEvent (wait_sig_inited);
sigtid = GetCurrentThreadId ();
- /* If we got something like a SIGINT while we were initializing, the
- signal thread should be waiting for this event. This signals the
- thread that it's ok to send the signal since the wait_sig thread
- is now active. */
- extern HANDLE console_handler_thread_waiter;
- SetEvent (console_handler_thread_waiter);
-
HANDLE catchem[] = {sigcatch_main, sigcatch_nonmain, sigcatch_nosync};
sigproc_printf ("Ready. dwProcessid %d", myself->dwProcessId);
for (;;)
@@ -1306,7 +1288,14 @@ wait_subproc (VOID *)
errloop = 0;
rc -= WAIT_OBJECT_0;
if (rc-- != 0)
- (void)proc_subproc (PROC_CHILDTERMINATED, rc);
+ {
+ (void) proc_subproc (PROC_CHILDTERMINATED, rc);
+ if (!proc_loop_wait) // Don't bother if wait_subproc is
+ break; // exiting
+
+ /* Send a SIGCHLD to myself. */
+ rc = sig_send (myself_nowait, SIGCHLD);
+ }
sigproc_printf ("looping");
}
@@ -1327,7 +1316,6 @@ WFSO (HANDLE hHandle, DWORD dwMilliseconds)
DWORD ret;
sigframe thisframe (mainthread);
ret = WaitForSingleObject (hHandle, dwMilliseconds);
-if (dwMilliseconds > 10 && ret == WAIT_TIMEOUT) system_printf ("TIMED OUT %d\n", dwMilliseconds);
return ret;
}
@@ -1339,7 +1327,6 @@ WFMO (DWORD nCount, CONST HANDLE *lpHandles, BOOL fWaitAll, DWORD dwMilliseconds
DWORD ret;
sigframe thisframe (mainthread);
ret = WaitForMultipleObjects (nCount, lpHandles, fWaitAll, dwMilliseconds);
-if (dwMilliseconds > 10 && ret == WAIT_TIMEOUT) system_printf ("TIMED OUT %d\n", dwMilliseconds);
return ret;
}
}