* dtable.cc (dtable::release): Check for socket. Change
cnt_need_fixup_before accordingly. (dtable::dup2): Ditto. (dtable::fixup_before_fork): New method. (dtable::fixup_before_exec): Ditto. * dtable.h (class dtable): Add member `cnt_need_fixup_before'. Add definition for methods `dec_need_fixup_before', `inc_need_fixup_before', `need_fixup_before', `fixup_before_exec' and `fixup_before_fork'. * fhandler.h (class fhandler_base): Slight rearrangements. Add definitions for methods `fixup_before_fork_exec'. (class fhandler_socket): Eliminate superfluous constructor. Add member `prot_info_ptr'. Add destructor. Add definitions for methods `dup', `fixup_before_fork_exec', `fixup_after_fork' and `fixup_after_exec'. * fork.cc (fork_parent): Care for file types which need a fixup before fork. Start child in suspended state then. * net.cc: New global variable `ws2_32_handle' and `wsadata'. (fdsock): Check for Winsock version. Call `set_socket_inheritance' only if Winsock version < 2.0. Care for `need_fixup' count in fdtab. (cygwin_socket): Eliminate call to `set_socket_inheritance'. (cygwin_accept): Ditto. (cygwin_rcmd): Ditto. (cygwin_rresvport): Ditto. (cygwin_rexec): Ditto. (socketpair): Ditto. (fhandler_socket::fhandler_socket): Set `need_fork_fixup'. Allocate space for the WSAPROTOCOL_INFOA struct used in fixup. (fhandler_socket::~fhandler_socket): New destructor. (fhandler_socket::fixup_before_fork_exec): New method. (fhandler_socket::fixup_after_fork): Ditto. (fhandler_socket::dup): Ditto. (wsock_init): New static function. (LoadDLLinitfunc (wsock32)): Rearranged. (LoadDLLinitfunc (ws2_32)): New function. (dummy_autoload): Add autoload statemants for `WSADuplicateSocketA' and `WSASocketA'. * spawn.cc (spawn_guts): Care for file types which need a fixup before exec. Start child in suspended state then.
This commit is contained in:
@@ -153,6 +153,8 @@ dtable::release (int fd)
|
||||
{
|
||||
if (!not_open (fd))
|
||||
{
|
||||
if ((fds[fd]->get_device () & FH_DEVMASK) == FH_SOCKET)
|
||||
dec_need_fixup_before ();
|
||||
delete fds[fd];
|
||||
fds[fd] = NULL;
|
||||
}
|
||||
@@ -377,6 +379,11 @@ dtable::dup2 (int oldfd, int newfd)
|
||||
if (!not_open (newfd))
|
||||
_close (newfd);
|
||||
fds[newfd] = newfh;
|
||||
|
||||
/* Count sockets. */
|
||||
if ((fds[newfd]->get_device () & FH_DEVMASK) == FH_SOCKET)
|
||||
inc_need_fixup_before ();
|
||||
|
||||
ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
|
||||
MALLOC_CHECK;
|
||||
|
||||
@@ -443,6 +450,34 @@ dtable::select_except (int fd, select_record *s)
|
||||
|
||||
/* Function to walk the fd table after an exec and perform
|
||||
per-fhandler type fixups. */
|
||||
void
|
||||
dtable::fixup_before_fork (DWORD target_proc_id)
|
||||
{
|
||||
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
|
||||
fhandler_base *fh;
|
||||
for (size_t i = 0; i < size; i++)
|
||||
if ((fh = fds[i]) != NULL)
|
||||
{
|
||||
debug_printf ("fd %d(%s)", i, fh->get_name ());
|
||||
fh->fixup_before_fork_exec (target_proc_id);
|
||||
}
|
||||
ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
|
||||
}
|
||||
|
||||
void
|
||||
dtable::fixup_before_exec (DWORD target_proc_id)
|
||||
{
|
||||
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
|
||||
fhandler_base *fh;
|
||||
for (size_t i = 0; i < size; i++)
|
||||
if ((fh = fds[i]) != NULL && (!fh->get_close_on_exec ()))
|
||||
{
|
||||
debug_printf ("fd %d(%s)", i, fh->get_name ());
|
||||
fh->fixup_before_fork_exec (target_proc_id);
|
||||
}
|
||||
ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
|
||||
}
|
||||
|
||||
void
|
||||
dtable::fixup_after_exec (HANDLE parent, size_t sz, fhandler_base **f)
|
||||
{
|
||||
|
Reference in New Issue
Block a user