From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2210) id 3A794393C857; Wed, 24 Feb 2021 13:00:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A794393C857 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Ken Brown To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: AF_UNIX: allow opening with the O_PATH flag X-Act-Checkin: newlib-cygwin X-Git-Author: Ken Brown X-Git-Refname: refs/heads/master X-Git-Oldrev: 2911d50e704f30b9017765e1c36c5492dcc50b30 X-Git-Newrev: 949fe7bec564f91818bad801bda47a4ddd58fadf Message-Id: <20210224130033.3A794393C857@sourceware.org> Date: Wed, 24 Feb 2021 13:00:33 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Feb 2021 13:00:33 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=949fe7bec564f91818bad801bda47a4ddd58fadf commit 949fe7bec564f91818bad801bda47a4ddd58fadf Author: Ken Brown Date: Tue Feb 23 11:48:46 2021 -0500 Cygwin: AF_UNIX: allow opening with the O_PATH flag This was done for the fhandler_socket_local class in commits 3a2191653a, 141437d374, and 477121317d, but the fhandler_socket_unix class was overlooked. Diff: --- winsup/cygwin/fhandler.h | 1 + winsup/cygwin/fhandler_socket_unix.cc | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 21e1df172..ad90cf33d 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1111,6 +1111,7 @@ class fhandler_socket_unix : public fhandler_socket int getsockname (struct sockaddr *name, int *namelen); int getpeername (struct sockaddr *name, int *namelen); int shutdown (int how); + int open (int flags, mode_t mode = 0); int close (); int getpeereid (pid_t *pid, uid_t *euid, gid_t *egid); ssize_t recvmsg (struct msghdr *msg, int flags); diff --git a/winsup/cygwin/fhandler_socket_unix.cc b/winsup/cygwin/fhandler_socket_unix.cc index 9f7f86c47..eedb0847e 100644 --- a/winsup/cygwin/fhandler_socket_unix.cc +++ b/winsup/cygwin/fhandler_socket_unix.cc @@ -1208,6 +1208,11 @@ fhandler_socket_unix::~fhandler_socket_unix () int fhandler_socket_unix::dup (fhandler_base *child, int flags) { + if (get_flags () & O_PATH) + /* We're viewing the socket as a disk file, but fhandler_base::dup + suffices here. */ + return fhandler_base::dup (child, flags); + if (fhandler_socket::dup (child, flags)) { __seterrno (); @@ -1801,9 +1806,23 @@ fhandler_socket_unix::shutdown (int how) return 0; } +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) + return open_fs (flags, mode); + + set_errno (EOPNOTSUPP); + return 0; +} + int fhandler_socket_unix::close () { + if (get_flags () & O_PATH) + return fhandler_base::close (); + HANDLE evt = InterlockedExchangePointer (&cwt_termination_evt, NULL); HANDLE thr = InterlockedExchangePointer (&connect_wait_thr, NULL); if (thr) @@ -2281,6 +2300,11 @@ fhandler_socket_unix::ioctl (unsigned int cmd, void *p) int fhandler_socket_unix::fcntl (int cmd, intptr_t arg) { + if (get_flags () & O_PATH) + /* We're viewing the socket as a disk file, but + fhandler_base::fcntl suffices here. */ + return fhandler_base::fcntl (cmd, arg); + int ret = -1; switch (cmd)