about summary refs log tree commit diff
path: root/sysdeps/mach/hurd/recvmsg.c
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2023-04-23 19:05:46 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-04-24 23:09:50 +0200
commit5fa8945605fc0fe8df5162e0945518c061dc5ba4 (patch)
tree7e9195da12e3a1e0584e8b6af1911ea66c1e9c84 /sysdeps/mach/hurd/recvmsg.c
parent0822e3552a787dd6ae352c3eb65783dfed2f4238 (diff)
downloadglibc-5fa8945605fc0fe8df5162e0945518c061dc5ba4.tar.gz
glibc-5fa8945605fc0fe8df5162e0945518c061dc5ba4.tar.xz
glibc-5fa8945605fc0fe8df5162e0945518c061dc5ba4.zip
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>
Diffstat (limited to 'sysdeps/mach/hurd/recvmsg.c')
-rw-r--r--sysdeps/mach/hurd/recvmsg.c4
1 files changed, 3 insertions, 1 deletions
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;