-2013-02-14 Glenn Morris <rgm@gnu.org>
+2013-02-15 Glenn Morris <rgm@gnu.org>
* modes.texi (Basic Major Modes): 'z' no longer bound in special-mode.
+2013-02-15 Eli Zaretskii <eliz@gnu.org>
+
+ * w32proc.c (new_child): Free up to 2 slots of dead processes at a
+ time. Improve diagnostics in DebPrint.
+ (reader_thread): If cp->char_avail is NULL, set the FILE_AT_EOF
+ flag, so that sys_select could have a chance of noticing that this
+ process is dead, and call a SIGCHLD handler for it. Improve
+ diagnostics in DebPrint.
+ (reap_subprocess): Reset the FILE_AT_EOF flag set by
+ reader_thread.
+ (sys_select): Watch a process whose procinfo.hProcess is non-NULL
+ even if its char_avail is NULL. Allows to reap subprocesses that
+ were forcibly deleted by delete-process. (Bug#13546)
+
+ * w32.c (sys_socket, sys_bind, sys_connect, sys_gethostname)
+ (sys_gethostbyname, sys_getservbyname, sys_getpeername)
+ (sys_shutdown, sys_setsockopt, sys_listen, sys_getsockname)
+ (sys_accept, sys_recvfrom, sys_sendto, fcntl): In case of failure,
+ make sure errno is set to an appropriate value. (Bug#13546)
+ (socket_to_fd): Add assertion against indexing fd_info[] with a
+ value that is out of bounds.
+ (sys_accept): If fd is negative, do not set up the child_process
+ structure for reading.
+
2013-02-15 Dmitry Antipov <dmantipov@yandex.ru>
* composite.c (fill_gstring_header): Remove useless prototype.
if (winsock_lib == NULL)
{
- h_errno = ENETDOWN;
+ errno = h_errno = ENETDOWN;
return INVALID_SOCKET;
}
s = pfn_socket (af, type, protocol);
if (s != INVALID_SOCKET)
- return socket_to_fd (s);
+ {
+ int retval = socket_to_fd (s);
+
+ if (retval == -1)
+ errno = h_errno;
+ return retval;
+ }
set_errno ();
return -1;
}
}
}
+ eassert (fd < MAXDESC);
fd_info[fd].hnd = (HANDLE) s;
/* set our own internal flags */
{
if (winsock_lib == NULL)
{
- h_errno = ENOTSOCK;
+ errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
set_errno ();
return rc;
}
- h_errno = ENOTSOCK;
+ errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
{
if (winsock_lib == NULL)
{
- h_errno = ENOTSOCK;
+ errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
set_errno ();
return rc;
}
- h_errno = ENOTSOCK;
+ errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
if (namelen > MAX_COMPUTERNAME_LENGTH)
return !GetComputerName (name, (DWORD *)&namelen);
- h_errno = EFAULT;
+ errno = h_errno = EFAULT;
return SOCKET_ERROR;
}
if (winsock_lib == NULL)
{
- h_errno = ENETDOWN;
+ errno = h_errno = ENETDOWN;
return NULL;
}
if (winsock_lib == NULL)
{
- h_errno = ENETDOWN;
+ errno = h_errno = ENETDOWN;
return NULL;
}
{
if (winsock_lib == NULL)
{
- h_errno = ENETDOWN;
+ errno = h_errno = ENETDOWN;
return SOCKET_ERROR;
}
set_errno ();
return rc;
}
- h_errno = ENOTSOCK;
+ errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
{
if (winsock_lib == NULL)
{
- h_errno = ENETDOWN;
+ errno = h_errno = ENETDOWN;
return SOCKET_ERROR;
}
set_errno ();
return rc;
}
- h_errno = ENOTSOCK;
+ errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
{
if (winsock_lib == NULL)
{
- h_errno = ENETDOWN;
+ errno = h_errno = ENETDOWN;
return SOCKET_ERROR;
}
set_errno ();
return rc;
}
- h_errno = ENOTSOCK;
+ errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
{
if (winsock_lib == NULL)
{
- h_errno = ENETDOWN;
+ errno = h_errno = ENETDOWN;
return SOCKET_ERROR;
}
fd_info[s].flags |= FILE_LISTEN;
return rc;
}
- h_errno = ENOTSOCK;
+ errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
{
if (winsock_lib == NULL)
{
- h_errno = ENETDOWN;
+ errno = h_errno = ENETDOWN;
return SOCKET_ERROR;
}
set_errno ();
return rc;
}
- h_errno = ENOTSOCK;
+ errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
{
if (winsock_lib == NULL)
{
- h_errno = ENETDOWN;
+ errno = h_errno = ENETDOWN;
return -1;
}
if (t == INVALID_SOCKET)
set_errno ();
else
- fd = socket_to_fd (t);
+ {
+ fd = socket_to_fd (t);
+ if (fd < 0)
+ errno = h_errno; /* socket_to_fd sets h_errno */
+ }
- fd_info[s].cp->status = STATUS_READ_ACKNOWLEDGED;
- ResetEvent (fd_info[s].cp->char_avail);
+ if (fd >= 0)
+ {
+ fd_info[s].cp->status = STATUS_READ_ACKNOWLEDGED;
+ ResetEvent (fd_info[s].cp->char_avail);
+ }
return fd;
}
- h_errno = ENOTSOCK;
+ errno = h_errno = ENOTSOCK;
return -1;
}
{
if (winsock_lib == NULL)
{
- h_errno = ENETDOWN;
+ errno = h_errno = ENETDOWN;
return SOCKET_ERROR;
}
set_errno ();
return rc;
}
- h_errno = ENOTSOCK;
+ errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
{
if (winsock_lib == NULL)
{
- h_errno = ENETDOWN;
+ errno = h_errno = ENETDOWN;
return SOCKET_ERROR;
}
set_errno ();
return rc;
}
- h_errno = ENOTSOCK;
+ errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
{
if (winsock_lib == NULL)
{
- h_errno = ENETDOWN;
+ errno = h_errno = ENETDOWN;
return -1;
}
return SOCKET_ERROR;
}
}
- h_errno = ENOTSOCK;
+ errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
goto Initialize;
if (child_proc_count == MAX_CHILDREN)
{
+ int i = 0;
+ child_process *dead_cp = NULL;
+
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)
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));
+ DebPrint (("new_child: Freeing slot of dead process %d, fd %d\n",
+ cp->procinfo.dwProcessId, cp->fd));
CloseHandle (cp->procinfo.hProcess);
cp->procinfo.hProcess = NULL;
CloseHandle (cp->procinfo.hThread);
cp->procinfo.hThread = NULL;
- goto Initialize;
+ /* Free up to 2 dead slots at a time, so that if we
+ have a lot of them, they will eventually all be
+ freed when the tornado ends. */
+ if (i == 0)
+ dead_cp = cp;
+ else
+ break;
+ i++;
}
}
+ if (dead_cp)
+ {
+ cp = dead_cp;
+ goto Initialize;
+ }
}
if (child_proc_count == MAX_CHILDREN)
return NULL;
if (cp->status == STATUS_READ_ERROR || !cp->char_avail)
break;
+ if (!CHILD_ACTIVE (cp) && cp->procinfo.hProcess && cp->fd >= 0)
+ {
+ /* Somebody already called delete_child on this child, since
+ only delete_child zeroes out cp->char_avail. This means
+ no one will read from cp->fd and will not set the
+ FILE_AT_EOF flag, therefore preventing sys_select from
+ noticing that the process died. Set the flag here
+ instead. */
+ fd_info[cp->fd].flags |= FILE_AT_EOF;
+ }
+
/* The name char_avail is a misnomer - it really just means the
read-ahead has completed, whether successfully or not. */
if (!SetEvent (cp->char_avail))
{
- DebPrint (("reader_thread.SetEvent failed with %lu for fd %ld\n",
- GetLastError (), cp->fd));
+ DebPrint (("reader_thread.SetEvent(0x%x) failed with %lu for fd %ld (PID %d)\n",
+ (DWORD_PTR)cp->char_avail, GetLastError (),
+ cp->fd, cp->pid));
return 1;
}
sys_read when the subprocess output is fully read. */
if (cp->fd < 0)
delete_child (cp);
+ else
+ {
+ /* Reset the flag set by reader_thread. */
+ fd_info[cp->fd].flags &= ~FILE_AT_EOF;
+ }
}
/* Wait for a child process specified by PID, or for any of our
/* Some child_procs might be sockets; ignore them. Also some
children may have died already, but we haven't finished reading
the process output; ignore them too. */
- if (CHILD_ACTIVE (cp) && cp->procinfo.hProcess
+ if ((CHILD_ACTIVE (cp) || cp->procinfo.hProcess)
&& (cp->fd < 0
|| (fd_info[cp->fd].flags & FILE_SEND_SIGCHLD) == 0
|| (fd_info[cp->fd].flags & FILE_AT_EOF) != 0)