Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2012-06-03 22:02:45 +0400
committerChristopher Faylor <me@cgf.cx>2012-06-03 22:02:45 +0400
commit3143cb7c00fc1b6f4d75a83ac28f3bfbc5d2e658 (patch)
treefb4a3fbfc0eea1168646125aca7fd53478418b00 /winsup/cygwin/syscalls.cc
parentff80d22a7c3d0d330c2892686aa694a080b109cb (diff)
* DevNotes: Add entry cgf-000011.
* fhandler.h (fhandler_base::refcnt): Delete. (fhandler_base::inc_refcnt): New function. (fhandler_base::dec_refcnt): New function. * cygheap.h (cygheap_fdnew::~cygheap_fdnew): Accommodate split of refcnt to inc_refcnt/dec_refcnt. (cygheap_fdget::cygheap_fdget): Ditto. (cygheap_fdget::~cygheap_fdget::cygheap_fdget): Ditto. * dtable.cc (dtable::release): Ditto. (cygwin_attach_handle_to_fd): Ditto. (dtable::init_std_file_from_handle): Ditto. (dtable::dup3): On success, return with fdtab locked. * dtable.h (dtable): Add dup_finish as a friend. * syscalls.cc (dup_finish): Define new function. Increment refcnt while fdtab is locked. (dup2): Use common dup_finish() to perform dup operation. (dup3): Ditto.
Diffstat (limited to 'winsup/cygwin/syscalls.cc')
-rw-r--r--winsup/cygwin/syscalls.cc20
1 files changed, 16 insertions, 4 deletions
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 657616ad9..3c0a02671 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -126,6 +126,18 @@ dup (int fd)
return res;
}
+inline int
+dup_finish (int oldfd, int newfd, int flags)
+{
+ int res;
+ if ((res = cygheap->fdtab.dup3 (oldfd, newfd, flags)) == newfd)
+ {
+ cygheap_fdget (newfd)->inc_refcnt ();
+ cygheap->fdtab.unlock (); /* dup3 exits with lock set on success */
+ }
+ return res;
+}
+
extern "C" int
dup2 (int oldfd, int newfd)
{
@@ -140,8 +152,8 @@ dup2 (int oldfd, int newfd)
cygheap_fdget cfd (oldfd);
res = (cfd >= 0) ? oldfd : -1;
}
- else if ((res = cygheap->fdtab.dup3 (oldfd, newfd, 0)) == newfd)
- cygheap->fdtab[newfd]->refcnt (1);
+ else
+ res = dup_finish (oldfd, newfd, 0);
syscall_printf ("%R = dup2(%d, %d)", res, oldfd, newfd);
return res;
@@ -162,8 +174,8 @@ dup3 (int oldfd, int newfd, int flags)
set_errno (cfd < 0 ? EBADF : EINVAL);
res = -1;
}
- else if ((res = cygheap->fdtab.dup3 (oldfd, newfd, flags)) == newfd)
- cygheap->fdtab[newfd]->refcnt (1);
+ else
+ res = dup_finish (oldfd, newfd, flags);
syscall_printf ("%R = dup3(%d, %d, %p)", res, oldfd, newfd, flags);
return res;