diff options
Diffstat (limited to 'winsup/cygwin/dtable.cc')
-rw-r--r-- | winsup/cygwin/dtable.cc | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index 2a9f8b078..15f4c0ce7 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -12,6 +12,7 @@ details. */ #define __INSIDE_CYGWIN_NET__ #include "winsup.h" +#include <sys/socket.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> @@ -242,7 +243,7 @@ dtable::release (int fd) { if (fds[fd]->need_fixup_before ()) dec_need_fixup_before (); - fds[fd]->dec_refcnt (); + fds[fd]->refcnt (-1); fds[fd] = NULL; if (fd <= 2) set_std_handle (fd); @@ -255,10 +256,8 @@ cygwin_attach_handle_to_fd (char *name, int fd, HANDLE handle, mode_t bin, if (fd == -1) fd = cygheap->fdtab.find_unused_handle (); fhandler_base *fh = build_fh_name (name); - if (!fh) - return -1; cygheap->fdtab[fd] = fh; - cygheap->fdtab[fd]->inc_refcnt (); + cygheap->fdtab[fd]->refcnt (1); fh->init (handle, myaccess, bin ?: fh->pc_binmode ()); return fd; } @@ -338,9 +337,6 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle) else fh = build_fh_name (name); - if (!fh) - return; - if (name[0]) { bin = fh->pc_binmode (); @@ -397,7 +393,7 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle) fh->open_setup (openflags); fh->usecount = 0; cygheap->fdtab[fd] = fh; - cygheap->fdtab[fd]->inc_refcnt (); + cygheap->fdtab[fd]->refcnt (1); set_std_handle (fd); paranoid_printf ("fd %d, handle %p", fd, handle); } @@ -529,7 +525,6 @@ fh_alloc (path_conv& pc) fh = cnew (fhandler_dev_random); break; case FH_MEM: - case FH_KMEM: case FH_PORT: fh = cnew (fhandler_dev_mem); break; @@ -607,15 +602,8 @@ fh_alloc (path_conv& pc) fh = cnew (fhandler_nodevice); else if (fh->dev () == FH_ERROR) { - if (!pc.isopen () && pc.dev.isfs ()) - fh->dev () = pc.dev; /* Special case: This file actually exists on - disk and we're not trying to open it so just - return the info from pc. */ - else - { - delete fh; - fh = NULL; - } + delete fh; + fh = NULL; } return fh; } @@ -712,15 +700,6 @@ dtable::dup3 (int oldfd, int newfd, int flags) MALLOC_CHECK; debug_printf ("dup3 (%d, %d, %p)", oldfd, newfd, flags); lock (); - bool do_unlock = true; - bool unlock_on_return; - if (!(flags & O_EXCL)) - unlock_on_return = true; /* Relinquish lock on return */ - else - { - flags &= ~O_EXCL; - unlock_on_return = false; /* Return with lock set on success */ - } if (not_open (oldfd)) { @@ -772,12 +751,10 @@ dtable::dup3 (int oldfd, int newfd, int flags) if ((res = newfd) <= 2) set_std_handle (res); - do_unlock = unlock_on_return; done: MALLOC_CHECK; - if (do_unlock) - unlock (); + unlock (); syscall_printf ("%R = dup3(%d, %d, %p)", res, oldfd, newfd, flags); return res; @@ -881,7 +858,7 @@ dtable::fixup_after_exec () /* Close the handle if it's close-on-exec or if an error was detected (typically with opening a console in a gui app) by fixup_after_exec. */ - if (fh->close_on_exec () || (!fh->nohandle () && !fh->get_io_handle ())) + if (fh->close_on_exec () || !fh->get_io_handle ()) fixup_close (i, fh); else if (fh->get_popen_pid ()) close (i); @@ -903,7 +880,7 @@ dtable::fixup_after_fork (HANDLE parent) { debug_printf ("fd %d (%s)", i, fh->get_name ()); fh->fixup_after_fork (parent); - if (!fh->nohandle () && !fh->get_io_handle ()) + if (!fh->get_io_handle ()) { /* This should actually never happen but it's here to make sure we don't crash due to access of an unopened file handle. */ |