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:
authorCorinna Vinschen <corinna@vinschen.de>2010-01-14 21:46:02 +0300
committerCorinna Vinschen <corinna@vinschen.de>2010-01-14 21:46:02 +0300
commite70fdfb99fb0e0a2558cd824ec37fd2fb2470335 (patch)
treede46419c870d5b7efd78b2855e3d244f380bf509 /winsup/cygwin/syscalls.cc
parent491912bffee21772288106de787c5dd5b26b0d9e (diff)
* cygwin.din (dup3): Export.
(pipe2): Export. * dtable.cc (dtable::dup_worker): Take additional flags parameter. Handle O_CLOEXEC flag. (dtable::dup3): Rename from dup2. Take additional flags parameter. Check for valid flags. Drop check for newfd == oldfd. * dtable.h (dtable::dup_worker): Add flags parameter. (dtable::dup3): Rename from dup2. * fcntl.cc (fcntl64): Add F_DUPFD_CLOEXEC case. * fhandler.h (fhandler_mailslot::get_object_attr): Add flags parameter. * fhandler.cc (fhandler_base::open): Use security attribute with inheritance according to setting of O_CLOEXEC flag. * fhandler_console.cc (fhandler_console::open): Ditto. * fhandler_fifo.cc (sec_user_cloexec): New inline function to create security attribute with inheritance according to setting of O_CLOEXEC flag. (fhandler_fifo::open): Call sec_user_cloexec to fetch security attribute. (fhandler_fifo::wait): Ditto. * fhandler_mem.cc (fhandler_dev_mem::open): Ditto. * fhandler_mailslot.cc (fhandler_mailslot::get_object_attr): Take additional flags parameter. Use security attribute with inheritance according to setting of O_CLOEXEC flag. (fhandler_mailslot::open): Call get_object_attr with flags parameter. * fhandler_registry.cc (fhandler_registry::open): Call set_close_on_exec on real handles to accommodate O_CLOEXEC flag. * fhandler_tty.cc (fhandler_tty_slave::open): Ditto. * fhandler_tape.cc: Create mutex with inheritance according to setting of O_CLOEXEC flag. * pipe.cc: Replace usage of O_NOINHERIT with O_CLOEXEC. (fhandler_pipe::init): Simplify setting close_on_exec flag. (fhandler_pipe::open): Remove setting close_on_exec flag. (fhandler_pipe::create): Use security attribute with inheritance according to setting of O_CLOEXEC flag. (pipe2): New exported function. * posix_ipc.cc: Throughout, open backing files with O_CLOEXEC flag to follow POSIX semantics. * security.h (sec_none_cloexec): New define. * syscalls.cc (dup): Add missing extern "C" qualifier. Accommodate renaming of dtable::dup2 to dtable::dup3. (dup2): Ditto. Check newfd == oldfd here. (dup3): New function. Check newfd == oldfd here. (open): Set close_on_exec flag according to O_CLOEXEC flag before calling fhandler->open. * include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
Diffstat (limited to 'winsup/cygwin/syscalls.cc')
-rw-r--r--winsup/cygwin/syscalls.cc60
1 files changed, 48 insertions, 12 deletions
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index ec589712a..bd3308a42 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -116,13 +116,13 @@ close_all_files (bool norelease)
cygheap->fdtab.unlock ();
}
-int
+extern "C" int
dup (int fd)
{
- return cygheap->fdtab.dup2 (fd, cygheap_fdnew ());
+ return cygheap->fdtab.dup3 (fd, cygheap_fdnew (), 0);
}
-int
+extern "C" int
dup2 (int oldfd, int newfd)
{
if (newfd >= OPEN_MAX_MAX)
@@ -131,7 +131,39 @@ dup2 (int oldfd, int newfd)
set_errno (EBADF);
return -1;
}
- return cygheap->fdtab.dup2 (oldfd, newfd);
+ if (newfd == oldfd)
+ {
+ cygheap_fdget cfd (oldfd);
+ if (cfd < 0)
+ {
+ syscall_printf ("-1 = dup2 (%d, %d) (oldfd not open)", oldfd, newfd);
+ return -1;
+ }
+ syscall_printf ("%d = dup2 (%d, %d) (newfd==oldfd)", oldfd, oldfd, newfd);
+ return oldfd;
+ }
+ return cygheap->fdtab.dup3 (oldfd, newfd, 0);
+}
+
+extern "C" int
+dup3 (int oldfd, int newfd, int flags)
+{
+ if (newfd >= OPEN_MAX_MAX)
+ {
+ syscall_printf ("-1 = dup3 (%d, %d, %p) (%d too large)",
+ oldfd, newfd, flags, newfd);
+ set_errno (EBADF);
+ return -1;
+ }
+ if (newfd == oldfd)
+ {
+ cygheap_fdget cfd (oldfd, false, false);
+ set_errno (cfd < 0 ? EBADF : EINVAL);
+ syscall_printf ("-1 = dup3 (%d, %d, %p) (newfd==oldfd)",
+ oldfd, newfd, flags);
+ return -1;
+ }
+ return cygheap->fdtab.dup3 (oldfd, newfd, flags);
}
static char desktop_ini[] =
@@ -1037,16 +1069,20 @@ open (const char *unix_path, int flags, ...)
delete fh;
res = -1;
}
- else if (!fh->open (flags, (mode & 07777) & ~cygheap->umask))
- {
- delete fh;
- res = -1;
- }
else
{
- cygheap->fdtab[fd] = fh;
- if ((res = fd) <= 2)
- set_std_handle (res);
+ fh->close_on_exec (flags & O_CLOEXEC);
+ if (!fh->open (flags, (mode & 07777) & ~cygheap->umask))
+ {
+ delete fh;
+ res = -1;
+ }
+ else
+ {
+ cygheap->fdtab[fd] = fh;
+ if ((res = fd) <= 2)
+ set_std_handle (res);
+ }
}
}
}