diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 7d3ab63ea..1d22e5c1b 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,14 @@ +Sat Nov 4 00:51:38 2000 Christopher Faylor + + * pinfo.cc (EnumProcessesNT): Avoid 0 pids. + (EnumProcesses9x): Ditto. + * sigproc.cc (remove_childe): Eliminate. + (proc_subproc): Move remove_child stuff here. + (wait_subproc): Synchronize with proc_subproc when error occurs. Add + more debugging info. + * sigproc.h (procstuff): Add an entry. + * spawn.cc (spawn_guts): Add sigframe here. + Fri Nov 3 20:07:14 2000 Christopher Faylor * sigproc.cc (wait_subproc): Refine debug output. diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index 89dd7469e..5b825e1a5 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -327,14 +327,17 @@ EnumProcessesNT (DWORD* &pidlist, DWORD &npidlist) SYSTEM_PROCESSES *px = procs; for (;;) { - if (nelem >= npidlist) + if (px->ProcessId) { - npidlist += slop_pidlist; - pidlist = (DWORD *) realloc (pidlist, size_pidlist (npidlist)); + if (nelem >= npidlist) + { + npidlist += slop_pidlist; + pidlist = (DWORD *) realloc (pidlist, size_pidlist (npidlist)); + } + pidlist[nelem++] = cygwin_pid (px->ProcessId); + if (!px->NextEntryDelta) + break; } - pidlist[nelem++] = cygwin_pid (px->ProcessId); - if (!px->NextEntryDelta) - break; px = (SYSTEM_PROCESSES *) ((char *) px + px->NextEntryDelta); } @@ -359,6 +362,8 @@ EnumProcesses9x (DWORD* &pidlist, DWORD &npidlist) if (myProcess32First(h, &proc)) do { + if (!proc.th32ProcessID) + continue; if (nelem >= npidlist) { npidlist += slop_pidlist; diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index e22861cfb..659a2c86d 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -116,7 +116,6 @@ int NO_COPY pending_signals = 0; // TRUE if signals pending static int __stdcall checkstate (waitq *); static __inline__ BOOL get_proc_lock (DWORD, DWORD); static HANDLE __stdcall getsem (_pinfo *, const char *, int, int); -static void __stdcall remove_child (int); static void __stdcall remove_zombie (int); static DWORD WINAPI wait_sig (VOID *arg); static int __stdcall stopped_or_terminated (waitq *, _pinfo *); @@ -285,7 +284,13 @@ proc_subproc (DWORD what, DWORD val) pchildren[val]->pid, val, hchildren[val], nchildren, nzombies); zombies[nzombies] = pchildren[val]; // Add to zombie array zombies[nzombies++]->process_state = PID_ZOMBIE;// Walking dead - remove_child (val); // Remove from children array + sigproc_printf ("removing [%d], pid %d, handle %p, nchildren %d", + val, pchildren[val]->pid, hchildren[val], nchildren); + if ((int) val < --nchildren) + { + hchildren[val] = hchildren[nchildren]; + pchildren[val] = pchildren[nchildren]; + } break; /* A child is in the stopped state. Scan wait() queue to see if anyone @@ -934,23 +939,6 @@ get_proc_lock (DWORD what, DWORD val) return TRUE; } -/* Remove a child from pchildren/hchildren by swapping it with the - * last child in the list. - */ -static void __stdcall -remove_child (int ci) -{ - sigproc_printf ("removing [%d], pid %d, handle %p, nchildren %d", - ci, pchildren[ci]->pid, hchildren[ci], nchildren); - if (ci < --nchildren) - { - pchildren[ci] = pchildren[nchildren]; - hchildren[ci] = hchildren[nchildren]; - } - - return; -} - /* Remove a zombie from zombies by swapping it with the last child in the list. */ static void __stdcall @@ -1250,7 +1238,9 @@ wait_subproc (VOID *) closed a handle in the children[] array. So, we try looping a couple of times to stabilize. FIXME - this is not foolproof. Probably, this thread should be responsible for closing the children. */ - if (++errloop < 10) + if (!errloop++) + proc_subproc (PROC_NOTHING, 0); // Just synchronize and continue + if (errloop < 10) continue; system_printf ("wait failed. nchildren %d, wait %d, %E", @@ -1262,9 +1252,10 @@ wait_subproc (VOID *) continue; else { - system_printf ("event[%d] %p, pchildren[%d] %p, %E", i, i, pchildren[i]); - system_printf ("pid %d, dwProcessId %u, progname '%s'", i, - events[0], pchildren[i]->pid, pchildren[i]->dwProcessId, + system_printf ("nchildren %d, event[%d] %p, pchildren[%d] %p, %E", + nchildren, i, events[0], i, (_pinfo *) pchildren[i]); + system_printf ("pid %d, dwProcessId %u, progname '%s'", + pchildren[i]->pid, pchildren[i]->dwProcessId, pchildren[i]->progname); } break; diff --git a/winsup/cygwin/sigproc.h b/winsup/cygwin/sigproc.h index 5a8e808fc..40f518777 100644 --- a/winsup/cygwin/sigproc.h +++ b/winsup/cygwin/sigproc.h @@ -20,7 +20,8 @@ enum procstuff PROC_CHILDSTOPPED = 2, // a child stopped PROC_CHILDTERMINATED = 3, // a child died PROC_CLEARWAIT = 4, // clear all waits - signal arrived - PROC_WAIT = 5 // setup for wait() for subproc + PROC_WAIT = 5, // setup for wait() for subproc + PROC_NOTHING = 6 // nothing, really }; typedef struct struct_waitq diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index dbd95d624..a430cf954 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -289,6 +289,7 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv, { BOOL rc; pid_t cygpid; + sigframe thisframe (mainthread); MALLOC_CHECK;