-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
cp: close file descriptors after cow on linux #2330
Conversation
Instead of using into_raw_fd(), which transfers ownership and requires us to close the file descriptor manually, use as_raw_fd(), which does not transfer ownership to us but drops the file descriptor when the original file is dropped (in our case at the end of the function).
Return current file descriptor limit: |
I have also found |
I think I have figured out a working solution (using rlimits), please check if it looks right... |
709b76f
to
8621b17
Compare
I don't know rust well enough to review that but I can say that it fixed the problem in NixOS when building ed with uutils-coreutils as gnu-coreutils replacement. |
@@ -724,6 +729,8 @@ pub struct UCommand { | |||
stdout: Option<Stdio>, | |||
stderr: Option<Stdio>, | |||
bytes_into_stdin: Option<Vec<u8>>, | |||
#[cfg(target_os = "linux")] | |||
limits: Vec<(rlimit::Resource, rlim, rlim)>, |
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.
smart (adding it as part of the test framework)
Instead of using into_raw_fd(), which transfers ownership and
requires us to close the file descriptor manually,
use as_raw_fd(), which does not transfer ownership to us but drops the
file descriptor when the original file is dropped (in our case at the
end of the function).
Closes #2312.
I tried to come up with a test for this, but I couldn't find a way to query the amount of file descriptors used, or to limit the number of open files for a test. If somebody could come up with a way to test this, that'd be awesome.