summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--winsup/cygwin/ChangeLog6
-rw-r--r--winsup/cygwin/dtable.cc10
-rw-r--r--winsup/cygwin/syscalls.cc2
3 files changed, 16 insertions, 2 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 39247a970..828bf09c7 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,11 @@
2012-06-03 Christopher Faylor <me.cygwin2012@cgf.cx>
+ * dtable.cc (dtable::dup3): Only return with lock set when O_EXCL flag
+ is passed in.
+ * syscalls.cc (dup_finish): Pass O_EXCL in flags to dtable::dup3.
+
+2012-06-03 Christopher Faylor <me.cygwin2012@cgf.cx>
+
* DevNotes: Add entry cgf-000011.
* fhandler.h (fhandler_base::refcnt): Delete.
(fhandler_base::inc_refcnt): New function.
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index 059d782d0..0ca64da2e 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -714,6 +714,14 @@ dtable::dup3 (int oldfd, int newfd, int flags)
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))
{
@@ -761,11 +769,11 @@ dtable::dup3 (int oldfd, int newfd, int flags)
goto done;
}
- do_unlock = false;
fds[newfd] = newfh;
if ((res = newfd) <= 2)
set_std_handle (res);
+ do_unlock = unlock_on_return;
done:
MALLOC_CHECK;
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 3c0a02671..2077a0a3c 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -130,7 +130,7 @@ inline int
dup_finish (int oldfd, int newfd, int flags)
{
int res;
- if ((res = cygheap->fdtab.dup3 (oldfd, newfd, flags)) == newfd)
+ if ((res = cygheap->fdtab.dup3 (oldfd, newfd, flags | O_EXCL)) == newfd)
{
cygheap_fdget (newfd)->inc_refcnt ();
cygheap->fdtab.unlock (); /* dup3 exits with lock set on success */