-
Notifications
You must be signed in to change notification settings - Fork 666
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
Add unistd::close_range()
#2153
Conversation
This allows efficiently closing (or marking "close on exec") many file descriptiors at once without needing procfs.
Thanks for your contribution to nix! I have left some comments :)
It would be great to test if this binding is properly working, we can test it with a single file descriptor with both |
flags: CloseRangeFlags, | ||
) -> Result<()> { | ||
let res = unsafe { | ||
libc::syscall( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't be using raw syscalls here. They lack type safety, and they aren't portable. Instead, you should add close_range
in a PR to libc. Then , once that merges, you can add support to Nix. If you're ambitious, you might consider adding closefrom
while you're at it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. I was following the precedent of other functions in this file (eg: gettid
, execveat
, and pivot_root
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, that makes sense.
For my use case I need to statically link and are therefore using musl which does not yet implement close_range()
.
BTW, the CI failure is because an
|
At this point it looks like I'd need to push the same This would leave very little benefit for my case for having the code in nix/libc and so I believe I'll just call Thank you both for taking the time to review this pull request, it was very pleasant to work with you for a moment and interact with the project. |
Allright, @cpick . I'll close this PR for now. Feel free to reopen if you ever change your mind. |
What does this PR do
This adds
close_range(2)
on Linux which allows efficiently closing (or marking "close on exec") many file descriptors at once without needing procfs.I have added comments, but am unsure if new tests are warranted. I have manually tested and used test programs and
strace
to validate that it is working as intended (both with and without various CLOSE_RANGE_* flag permutations.Checklist:
CONTRIBUTING.md