summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2013-02-13 19:04:30 +0200
committerEli Zaretskii <eliz@gnu.org>2013-02-13 19:04:30 +0200
commit0e4e7b741b515be091e2ec3b3ff63f1b16084555 (patch)
treee9c3944bb91f44bf0375e62cc7e8d93e97c2300e /src
parent6e432f0cda1daa7bcee1fb5872dcfa130abe5018 (diff)
downloademacs-0e4e7b741b515be091e2ec3b3ff63f1b16084555.tar.gz
More robust creation of a subprocess, attempt to solve bug #13546.
src/w32proc.c (new_child): If no vacant slots are found in child_procs[], make another pass looking for slots whose process has exited or died.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog4
-rw-r--r--src/w32proc.c27
2 files changed, 31 insertions, 0 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 358f25b40f9..e1b8a23e6b2 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,9 @@
2013-02-13 Eli Zaretskii <eliz@gnu.org>
+ * w32proc.c (new_child): If no vacant slots are found in
+ child_procs[], make another pass looking for slots whose process
+ has exited or died. (Bug#13546)
+
* w32.c (sys_pipe): When failing due to file descriptors above
MAXDESC, set errno to EMFILE.
(_sys_read_ahead): Update cp->status when failing to read serial
diff --git a/src/w32proc.c b/src/w32proc.c
index 8c09a1b1beb..1e72d41e16b 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -798,6 +798,33 @@ new_child (void)
if (!CHILD_ACTIVE (cp) && cp->procinfo.hProcess == NULL)
goto Initialize;
if (child_proc_count == MAX_CHILDREN)
+ {
+ DebPrint (("new_child: No vacant slots, looking for dead processes\n"));
+ for (cp = child_procs + (child_proc_count-1); cp >= child_procs; cp--)
+ if (!CHILD_ACTIVE (cp) && cp->procinfo.hProcess)
+ {
+ DWORD status = 0;
+
+ if (!GetExitCodeProcess (cp->procinfo.hProcess, &status))
+ {
+ DebPrint (("new_child.GetExitCodeProcess: error %lu for PID %lu\n",
+ GetLastError (), cp->procinfo.dwProcessId));
+ status = STILL_ACTIVE;
+ }
+ if (status != STILL_ACTIVE
+ || WaitForSingleObject (cp->procinfo.hProcess, 0) == WAIT_OBJECT_0)
+ {
+ DebPrint (("new_child: Freeing slot of dead process %d\n",
+ cp->procinfo.dwProcessId));
+ CloseHandle (cp->procinfo.hProcess);
+ cp->procinfo.hProcess = NULL;
+ CloseHandle (cp->procinfo.hThread);
+ cp->procinfo.hThread = NULL;
+ goto Initialize;
+ }
+ }
+ }
+ if (child_proc_count == MAX_CHILDREN)
return NULL;
cp = &child_procs[child_proc_count++];