[newlib-cygwin] Cygwin: AF_LOCAL: allow opening with the O_PATH flag
Ken Brown
kbrown@sourceware.org
Thu Jan 30 14:44:00 GMT 2020
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=3a2191653ac979f494aa2797942bd96414cedde8
commit 3a2191653ac979f494aa2797942bd96414cedde8
Author: Ken Brown <kbrown@cornell.edu>
Date: Thu Jan 23 14:39:15 2020 -0500
Cygwin: AF_LOCAL: allow opening with the O_PATH flag
If that flag is not set, or if an attempt is made to open a different
type of socket, the errno is now EOPNOTSUPP instead of ENXIO. This is
consistent with POSIX, starting with the 2016 edition. Earlier
editions were silent on this issue.
Opening is done in a (new) fhandler_socket_local::open method by
calling fhandler_base::open_fs.
Also add a corresponding fhandler_socket_local::close method.
Diff:
---
winsup/cygwin/fhandler.h | 2 ++
winsup/cygwin/fhandler_socket_local.cc | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 80a78d1..c54780e 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -834,6 +834,8 @@ class fhandler_socket_local: public fhandler_socket_wsock
int getsockopt (int level, int optname, const void *optval,
__socklen_t *optlen);
+ int open (int flags, mode_t mode = 0);
+ int close ();
int __reg2 fstat (struct stat *buf);
int __reg2 fstatvfs (struct statvfs *buf);
int __reg1 fchmod (mode_t newmode);
diff --git a/winsup/cygwin/fhandler_socket_local.cc b/winsup/cygwin/fhandler_socket_local.cc
index f88ced2..e7f4fe6 100644
--- a/winsup/cygwin/fhandler_socket_local.cc
+++ b/winsup/cygwin/fhandler_socket_local.cc
@@ -634,6 +634,26 @@ fhandler_socket_local::dup (fhandler_base *child, int flags)
return fhandler_socket_wsock::dup (child, flags);
}
+int
+fhandler_socket_local::open (int flags, mode_t mode)
+{
+ /* We don't support opening sockets unless O_PATH is specified. */
+ if (flags & O_PATH)
+ return open_fs (flags, mode);
+
+ set_errno (EOPNOTSUPP);
+ return 0;
+}
+
+int
+fhandler_socket_local::close ()
+{
+ if (get_flags () & O_PATH)
+ return fhandler_base::close ();
+ else
+ return fhandler_socket_wsock::close ();
+}
+
int __reg2
fhandler_socket_local::fstat (struct stat *buf)
{
More information about the Cygwin-cvs
mailing list