Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using MSG_CMSG_CLOEXEC flag #16

Open
FuuuOverclocking opened this issue Oct 9, 2024 · 3 comments
Open

Consider using MSG_CMSG_CLOEXEC flag #16

FuuuOverclocking opened this issue Oct 9, 2024 · 3 comments

Comments

@FuuuOverclocking
Copy link

MSG_CMSG_CLOEXEC (recvmsg() only; since Linux 2.6.23)
              Set the close-on-exec flag for the file descriptor
              received via a UNIX domain file descriptor using the
              SCM_RIGHTS operation (described in [unix(7)](https://man7.org/linux/man-pages/man7/unix.7.html)).  This flag is
              useful for the same reasons as the O_CLOEXEC flag of
              [open(2)](https://man7.org/linux/man-pages/man2/open.2.html).

Consider using MSG_CMSG_CLOEXEC flag, close-on-exec should be default behavior.

Links:

@FuuuOverclocking
Copy link
Author

#17

@cbranch
Copy link

cbranch commented Nov 6, 2024

Rust-created files and sockets have O_CLOEXEC set, e.g.
https://github.com/rust-lang/rust/blob/4d215e2426d52ca8d1af166d5f6b5e172afbff67/library/std/src/sys/pal/unix/fs.rs#L1177
https://github.com/rust-lang/rust/blob/4d215e2426d52ca8d1af166d5f6b5e172afbff67/library/std/src/sys/pal/unix/net.rs#L85

While it may not be possible to set this on non-Linux systems as part of the recvmsg call, this crate should either set it immediately on reception of the file descriptors, or else document that the returned file descriptors do not have this flag set.

@nagisa
Copy link
Collaborator

nagisa commented Nov 6, 2024

I'm happy to take a PR that implements it in a portable way (even if the implementation ends up slightly racy.)

MSG_CMSG_CLOEXEC is supported on Linux, FreeBSD and various other BSDs but notably not on Darwin. So a fallback will be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants