summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/dtable.cc
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/dtable.cc')
-rw-r--r--winsup/cygwin/dtable.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index b08d547b8..4df56993c 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -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;
@@ -444,6 +451,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)
{
size = sz;