[PATCH] Cygwin: fhandler_socket::open: support the O_PATH flag

Ken Brown kbrown@cornell.edu
Thu Dec 26 15:25:00 GMT 2019


If that flag is not set, fail with EOPNOTSUPP instead of ENXIO.  This
is consistent with POSIX, starting with the 2016 edition.  Earlier
editions were silent on this issue.
---
 winsup/cygwin/fhandler_socket.cc | 13 +++++++++++--
 winsup/cygwin/release/3.1.3      |  5 +++++
 winsup/doc/new-features.xml      |  5 +++++
 3 files changed, 21 insertions(+), 2 deletions(-)
 create mode 100644 winsup/cygwin/release/3.1.3

diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc
index 9f33d8087..4a46d5a64 100644
--- a/winsup/cygwin/fhandler_socket.cc
+++ b/winsup/cygwin/fhandler_socket.cc
@@ -269,8 +269,17 @@ fhandler_socket::fcntl (int cmd, intptr_t arg)
 int
 fhandler_socket::open (int flags, mode_t mode)
 {
-  set_errno (ENXIO);
-  return 0;
+  /* We don't support opening sockets unless O_PATH is specified. */
+  if (!(flags & O_PATH))
+    {
+      set_errno (EOPNOTSUPP);
+      return 0;
+    }
+
+  query_open (query_read_attributes);
+  nohandle (true);
+  set_flags (flags);
+  return 1;
 }
 
 int __reg2
diff --git a/winsup/cygwin/release/3.1.3 b/winsup/cygwin/release/3.1.3
new file mode 100644
index 000000000..8755c93df
--- /dev/null
+++ b/winsup/cygwin/release/3.1.3
@@ -0,0 +1,5 @@
+What changed:
+-------------
+
+- Sockets can now be opened with the O_PATH flag.  If that flag is not
+  specified, the errno is now EOPNOTSUPP instead of ENXIO.
diff --git a/winsup/doc/new-features.xml b/winsup/doc/new-features.xml
index 65bdc17ab..c8b48d1ca 100644
--- a/winsup/doc/new-features.xml
+++ b/winsup/doc/new-features.xml
@@ -54,6 +54,11 @@ Allow times(2) to have a NULL argument, as on Linux.
 Improve /proc/cpuinfo output and align more closely with Linux.
 </para></listitem>
 
+<listitem><para>
+Sockets can now be opened with the O_PATH flag.  If that flag is not
+specified, the errno is now EOPNOTSUPP instead of ENXIO.
+</para></listitem>
+
 </itemizedlist>
 
 </sect2>
-- 
2.21.0



More information about the Cygwin-patches mailing list