This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH] Cygwin: allow opening an AF_LOCAL/AF_UNIX socket with O_PATH
- From: Ken Brown <kbrown at cornell dot edu>
- To: "cygwin-patches at cygwin dot com" <cygwin-patches at cygwin dot com>
- Date: Thu, 16 Jan 2020 18:34:18 +0000
- Subject: [PATCH] Cygwin: allow opening an AF_LOCAL/AF_UNIX socket with O_PATH
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cornell.edu; dmarc=pass action=none header.from=cornell.edu; dkim=pass header.d=cornell.edu; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5w+1iAKgf8ViM2rweIEmyYB2uLEnTTfXt2KObjiaAzM=; b=nd+WIFA7HuHRxSQQOKB4PMvBG4rKn/0QDYb0flIZj8BIZyvM6hT47G1pB0o4YNMryL+PXjy2SnUqdPvMJVdkC34SdWyzt4Lp778TpS3yMQMWh9aysRqgFu53aKeQHuYtQvxJjJ0X/BdIpVaWY9YLMgN69ZCjzmi/OlEn1GbMid5brz0sNxkNbTaVOWGe3vKfJ/nO/xAjjU7jT14vEc4tLaAaijEmdHQs7MTXzPiNdzuJvrQ2lPkAVDG0CGAUyGWKeQQersLlSMSNOE0ybvW/PFCdaI86shBmDo5oD2rbWTxNwxvBbkkRC8+4Qaags/AbqHIRYxBSerx8Qu/vc7ohVA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZkeEI3XOFncGjsTJ5T5Q2FOZ3L3u4A7YIZjShaSAl0dqD9SSzjj1cY04BILiUWJs37rEF9nnOZSAnkS997bJgU39KAscPhPhHyUsD+mPn+qOD/7gvZaTtTfDd/gslifaoX2lvOF3wg8jfmDquB1/KlyQKli2ltsAnXWxUW2jqpi6RdmCkyAHLdKmtKey3VU9t+qEFUvnCJOSKt/82vpmoQkHtZIeIz1pPvmD2IwZKYgVdb4W9QBs1DY2zOVHQinZmr7Hgq5hlGq+BlSrfZLluyNX/cHCUX0B/e4yKfwZibKoDI5sqdTkDBxtCS14jHo8zHwJXKdAtHcVcU21SMZm1w==
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.
---
winsup/cygwin/fhandler.h | 2 ++
winsup/cygwin/fhandler_socket.cc | 2 +-
winsup/cygwin/fhandler_socket_local.cc | 16 ++++++++++++++++
winsup/cygwin/fhandler_socket_unix.cc | 16 ++++++++++++++++
winsup/cygwin/release/3.1.3 | 7 +++++++
winsup/doc/new-features.xml | 6 ++++++
6 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index c0d56b4da..71b549d38 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -822,6 +822,7 @@ 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 __reg2 fstat (struct stat *buf);
int __reg2 fstatvfs (struct statvfs *buf);
int __reg1 fchmod (mode_t newmode);
@@ -1103,6 +1104,7 @@ class fhandler_socket_unix : public fhandler_socket
virtual int ioctl (unsigned int cmd, void *);
virtual int fcntl (int cmd, intptr_t);
+ int open (int flags, mode_t mode = 0);
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.cc b/winsup/cygwin/fhandler_socket.cc
index 9f33d8087..227004b43 100644
--- a/winsup/cygwin/fhandler_socket.cc
+++ b/winsup/cygwin/fhandler_socket.cc
@@ -269,7 +269,7 @@ fhandler_socket::fcntl (int cmd, intptr_t arg)
int
fhandler_socket::open (int flags, mode_t mode)
{
- set_errno (ENXIO);
+ set_errno (EOPNOTSUPP);
return 0;
}
diff --git a/winsup/cygwin/fhandler_socket_local.cc b/winsup/cygwin/fhandler_socket_local.cc
index f88ced22d..dbca74702 100644
--- a/winsup/cygwin/fhandler_socket_local.cc
+++ b/winsup/cygwin/fhandler_socket_local.cc
@@ -634,6 +634,22 @@ 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))
+ {
+ set_errno (EOPNOTSUPP);
+ return 0;
+ }
+
+ query_open (query_read_attributes);
+ nohandle (true);
+ set_flags (flags);
+ return 1;
+}
+
int __reg2
fhandler_socket_local::fstat (struct stat *buf)
{
diff --git a/winsup/cygwin/fhandler_socket_unix.cc b/winsup/cygwin/fhandler_socket_unix.cc
index eea7e76b3..b3d4da49a 100644
--- a/winsup/cygwin/fhandler_socket_unix.cc
+++ b/winsup/cygwin/fhandler_socket_unix.cc
@@ -2296,6 +2296,22 @@ fhandler_socket_unix::fcntl (int cmd, intptr_t arg)
return ret;
}
+int
+fhandler_socket_unix::open (int flags, mode_t mode)
+{
+ /* 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
fhandler_socket_unix::fstat (struct stat *buf)
{
diff --git a/winsup/cygwin/release/3.1.3 b/winsup/cygwin/release/3.1.3
index 489741136..af9e0f38e 100644
--- a/winsup/cygwin/release/3.1.3
+++ b/winsup/cygwin/release/3.1.3
@@ -1,3 +1,10 @@
+What's new:
+-----------
+
+- AF_LOCAL/AF_UNIX sockets can now be opened 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.
+
Bug Fixes
---------
diff --git a/winsup/doc/new-features.xml b/winsup/doc/new-features.xml
index 65bdc17ab..bf481bd04 100644
--- a/winsup/doc/new-features.xml
+++ b/winsup/doc/new-features.xml
@@ -54,6 +54,12 @@ 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>
+AF_LOCAL/AF_UNIX sockets can now be opened 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.
+</para></listitem>
+
</itemizedlist>
</sect2>
--
2.21.0