diff options
author | Christopher Faylor <me@cgf.cx> | 2012-02-01 17:20:02 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2012-02-01 17:20:02 +0000 |
commit | 8fa8b3a3891165dc4c8eb8f05923a3352b20aec3 (patch) | |
tree | 999711e4be4cb1ba45294c113a1741f8263dfde4 | |
parent | 4c68bf65c8b225f96c4cea4417ffd3a0dd0341e4 (diff) | |
download | cygnal-8fa8b3a3891165dc4c8eb8f05923a3352b20aec3.tar.gz cygnal-8fa8b3a3891165dc4c8eb8f05923a3352b20aec3.tar.bz2 cygnal-8fa8b3a3891165dc4c8eb8f05923a3352b20aec3.zip |
* dtable.cc (dtable::dup_worker): Add comment explaining why refcnt isn't
incremented here.
(dtable::dup3): Simplify slightly. Add comment.
* syscalls.cc (dup3): Increment refcnt here, similarly to dup2.
-rw-r--r-- | winsup/cygwin/ChangeLog | 7 | ||||
-rw-r--r-- | winsup/cygwin/dtable.cc | 10 | ||||
-rw-r--r-- | winsup/cygwin/syscalls.cc | 5 |
3 files changed, 17 insertions, 5 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 384c99be5..a774fee02 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,12 @@ 2012-02-01 Christopher Faylor <me.cygwin2012@cgf.cx> + * dtable.cc (dtable::dup_worker): Add comment explaining why refcnt + isn't incremented here. + (dtable::dup3): Simplify slightly. Add comment. + * syscalls.cc (dup3): Increment refcnt here, similarly to dup2. + +2012-02-01 Christopher Faylor <me.cygwin2012@cgf.cx> + * fhandler.cc (fhandler_base_overlapped::has_ongoing_io): Don't block GetOverlappedResult since previous IsEventSignalled will have reset the handle. diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index ba0045f9e..c0af76961 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -669,8 +669,12 @@ dtable::dup_worker (fhandler_base *oldfh, int flags) } else { + /* Don't increment refcnt here since we don't know if this is a + allocated fd. So we leave this chore to the caller. */ + newfh->usecount = 0; newfh->archetype_usecount (1); + /* The O_CLOEXEC flag enforces close-on-exec behaviour. */ newfh->set_close_on_exec (!!(flags & O_CLOEXEC)); debug_printf ("duped '%s' old %p, new %p", oldfh->get_name (), oldfh->get_io_handle (), newfh->get_io_handle ()); @@ -735,9 +739,9 @@ dtable::dup3 (int oldfd, int newfd, int flags) if (!not_open (newfd)) close (newfd); - else if ((size_t) newfd < size) - /* nothing to do */; - else if (find_unused_handle (newfd) < 0) + else if ((size_t) newfd > size + && find_unused_handle (newfd) < 0) + /* couldn't extend fdtab */ { newfh->close (); res = -1; diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 4ff64a3e3..3ed0f4f95 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -161,8 +161,9 @@ dup3 (int oldfd, int newfd, int flags) set_errno (cfd < 0 ? EBADF : EINVAL); res = -1; } - else - res = cygheap->fdtab.dup3 (oldfd, newfd, flags); + else if ((res = cygheap->fdtab.dup3 (oldfd, newfd, flags)) == newfd) + cygheap->fdtab[newfd]->refcnt (1); + syscall_printf ("%R = dup3(%d, %d, %p)", res, oldfd, newfd, flags); return res; } |