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 1/4] hurd: Don't pass FD_CLOEXEC in CMSG_DATA
Date: Mon, 24 Apr 2023 23:01:59 +0200 [thread overview]
Message-ID: <20230424210159.xdmwk5oqfflwph2k@begin> (raw)
In-Reply-To: <20230423160548.126576-1-bugaevc@gmail.com>
Sergey Bugaev, le dim. 23 avril 2023 19:05:45 +0300, a ecrit:
> It is of no concern to the receiving process whether or not the sender
> process wants to close its copy of sent file descriptor upon exec, and
> it should not influence whether or not the received file descriptor gets
> the FD_CLOEXEC flag set in the receiving process.
>
> The latter should in fact be dependent on the MSG_CMSG_CLOEXEC flag
> being passed to the recvmsg () call, which is going to be implemented
> in the following commit.
>
> Fixes 344e755248ce02c0f8d095d11cc49e340703d926
> "hurd: Support sending file descriptors over Unix sockets"
>
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
> ---
> sysdeps/mach/hurd/recvmsg.c | 5 +++--
> sysdeps/mach/hurd/sendmsg.c | 7 +++++--
> 2 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/sysdeps/mach/hurd/recvmsg.c b/sysdeps/mach/hurd/recvmsg.c
> index 39de86f6..c08eb499 100644
> --- a/sysdeps/mach/hurd/recvmsg.c
> +++ b/sysdeps/mach/hurd/recvmsg.c
> @@ -189,7 +189,8 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags)
> if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
> {
> /* SCM_RIGHTS support. */
> - /* The fd's flags are passed in the control data. */
> + /* The fd's flags are passed in the control data, but there currently
> + aren't any defined other than FD_CLOEXEC which we don't respect. */
> int *fds = (int *) CMSG_DATA (cmsg);
> nfds = (cmsg->cmsg_len - CMSG_ALIGN (sizeof (struct cmsghdr)))
> / sizeof (int);
> @@ -200,7 +201,7 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags)
> if (err)
> goto cleanup;
> fds[j] = opened_fds[newfds] = _hurd_intern_fd (newports[newfds],
> - fds[j], 0);
> + 0, 0);
The two patches actually make me realize that there was a confusion here
between FD_* flags and O_* flags. _hurd_intern_fd definitely takes O_*
flags (and translates O_CLOEXEC to FD_CLOEXEC). If we are to transport
some flags, it'd probably rather be O_* flags. I'll commit that way.
> if (fds[j] == -1)
> {
> err = errno;
> diff --git a/sysdeps/mach/hurd/sendmsg.c b/sysdeps/mach/hurd/sendmsg.c
> index 5871d1d8..2f19797b 100644
> --- a/sysdeps/mach/hurd/sendmsg.c
> +++ b/sysdeps/mach/hurd/sendmsg.c
> @@ -138,8 +138,11 @@ __libc_sendmsg (int fd, const struct msghdr *message, int flags)
> 0, 0, 0, 0);
> if (! err)
> nports++;
> - /* We pass the flags in the control data. */
> - fds[i] = descriptor->flags;
> + /* We pass the file descriptor flags in the control data.
> + The only currently defined flag is FD_CLOEXEC, which we
> + don't want to pass and so we mask it out, so this will
> + always be 0 currently. */
> + fds[i] = descriptor->flags & ~FD_CLOEXEC;
> err;
> }));
>
> --
> 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:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-23 16:05 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
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 ` Samuel Thibault [this message]
2023-04-24 21:13 ` [PATCH v2 1/4] hurd: Don't pass FD_CLOEXEC in CMSG_DATA 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=20230424210159.xdmwk5oqfflwph2k@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).