From: Samuel Thibault <samuel.thibault@gnu.org>
To: Sergey Bugaev <bugaevc@gmail.com>
Cc: libc-alpha@sourceware.org, bug-hurd@gnu.org
Subject: Re: [PATCH v2 2/4] hurd: Implement MSG_CMSG_CLOEXEC
Date: Mon, 24 Apr 2023 23:10:09 +0200 [thread overview]
Message-ID: <20230424211009.3dbv745qz36vmkpi@begin> (raw)
In-Reply-To: <20230423160548.126576-2-bugaevc@gmail.com>
Applied, thanks!
Sergey Bugaev, le dim. 23 avril 2023 19:05:46 +0300, a ecrit:
> 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>
> ---
> sysdeps/mach/hurd/bits/socket.h | 5 ++++-
> sysdeps/mach/hurd/recvmsg.c | 3 ++-
> 2 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/sysdeps/mach/hurd/bits/socket.h b/sysdeps/mach/hurd/bits/socket.h
> index 2d78a916..c2392bed 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 c08eb499..9a37a053 100644
> --- a/sysdeps/mach/hurd/recvmsg.c
> +++ b/sysdeps/mach/hurd/recvmsg.c
> @@ -197,11 +197,12 @@ __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],
> - 0, 0);
> + fd_flags, 0);
> if (fds[j] == -1)
> {
> err = errno;
> --
> 2.40.0
>
--
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.
next prev parent reply other threads:[~2023-04-24 21:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-23 16:05 [PATCH v2 1/4] hurd: Don't pass FD_CLOEXEC in CMSG_DATA Sergey Bugaev
2023-04-23 16:05 ` [PATCH v2 2/4] hurd: Implement MSG_CMSG_CLOEXEC Sergey Bugaev
2023-04-24 21:10 ` Samuel Thibault [this message]
2023-04-24 21:35 ` Sergey Bugaev
2023-04-24 22:18 ` Samuel Thibault
2023-04-23 16:05 ` [PATCH v2 3/4] hurd: Only deallocate addrport when it's valid Sergey Bugaev
2023-04-24 20:44 ` Samuel Thibault
2023-04-23 16:05 ` [PATCH v2 4/4] socket: Add a test for MSG_CMSG_CLOEXEC Sergey Bugaev
2023-04-24 22:21 ` Samuel Thibault
2023-04-24 21:01 ` [PATCH v2 1/4] hurd: Don't pass FD_CLOEXEC in CMSG_DATA Samuel Thibault
2023-04-24 21:13 ` Sergey Bugaev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230424211009.3dbv745qz36vmkpi@begin \
--to=samuel.thibault@gnu.org \
--cc=bug-hurd@gnu.org \
--cc=bugaevc@gmail.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).