public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] hurd: Implement MSG_CMSG_CLOEXEC
@ 2023-04-24 21:10 Samuel Thibault
  0 siblings, 0 replies; only message in thread
From: Samuel Thibault @ 2023-04-24 21:10 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5fa8945605fc0fe8df5162e0945518c061dc5ba4

commit 5fa8945605fc0fe8df5162e0945518c061dc5ba4
Author: Sergey Bugaev <bugaevc@gmail.com>
Date:   Sun Apr 23 19:05:46 2023 +0300

    hurd: Implement MSG_CMSG_CLOEXEC
    
    This is a new flag that can be passed to recvmsg () to make it
    atomically set the CLOEXEC flag on all the file descriptors received
    using the SCM_RIGHTS mechanism. This is useful for all the same reasons
    that the other XXX_CLOEXEC flags are useful: namely, it provides
    atomicity with respect to another thread of the same process calling
    (fork and then) exec at the same time.
    
    This flag is already supported on Linux and FreeBSD. The flag's value,
    0x40000, is choosen to match FreeBSD's.
    
    Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
    Message-Id: <20230423160548.126576-2-bugaevc@gmail.com>

Diff:
---
 sysdeps/mach/hurd/bits/socket.h | 5 ++++-
 sysdeps/mach/hurd/recvmsg.c     | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/sysdeps/mach/hurd/bits/socket.h b/sysdeps/mach/hurd/bits/socket.h
index 2d78a9167c..c2392bed80 100644
--- a/sysdeps/mach/hurd/bits/socket.h
+++ b/sysdeps/mach/hurd/bits/socket.h
@@ -197,8 +197,11 @@ enum
 #define MSG_WAITALL MSG_WAITALL
     MSG_DONTWAIT	= 0x80,	/* This message should be nonblocking.  */
 #define MSG_DONTWAIT MSG_DONTWAIT
-    MSG_NOSIGNAL	= 0x0400	/* Do not generate SIGPIPE on EPIPE.  */
+    MSG_NOSIGNAL	= 0x0400,	/* Do not generate SIGPIPE on EPIPE.  */
 #define MSG_NOSIGNAL MSG_NOSIGNAL
+    MSG_CMSG_CLOEXEC	= 0x40000	/* Atomically set close-on-exec flag
+					   for file descriptors in SCM_RIGHTS.  */
+#define MSG_CMSG_CLOEXEC MSG_CMSG_CLOEXEC
   };
 
 
diff --git a/sysdeps/mach/hurd/recvmsg.c b/sysdeps/mach/hurd/recvmsg.c
index 90fd2698c0..e06b0fe3ba 100644
--- a/sysdeps/mach/hurd/recvmsg.c
+++ b/sysdeps/mach/hurd/recvmsg.c
@@ -197,11 +197,13 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags)
 
 	for (j = 0; j < nfds; j++)
 	  {
+	    int fd_flags = (flags & MSG_CMSG_CLOEXEC) ? O_CLOEXEC : 0;
 	    err = reauthenticate (ports[i], &newports[newfds]);
 	    if (err)
 	      goto cleanup;
 	    fds[j] = opened_fds[newfds] = _hurd_intern_fd (newports[newfds],
-							   fds[j], 0);
+							   fds[j] | fd_flags,
+							   0);
 	    if (fds[j] == -1)
 	      {
 		err = errno;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-24 21:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-24 21:10 [glibc] hurd: Implement MSG_CMSG_CLOEXEC Samuel Thibault

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).