-
Notifications
You must be signed in to change notification settings - Fork 674
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 getrlimit and setrlimit #1302
Conversation
You need to fix the test failures. First of all, |
Clicked the wrong button... Will fix the issues. |
323b5a4
to
e85d4ed
Compare
Fixed the test errors. Please review. Thank you @asomers |
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.
Rather than define Resource
twice for different platforms, which doesn't even handle all platform-specificities, I think you should define Resource
only once, and gate each enum item with an appropriate #[cfg(...)]
.
I haven't reviewed the tests yet. ENOTIME.
Thank you for the suggestion. But I am not sure when enum can be both libc_enum!{
pub enum ResourceDemo {
#[cfg(all(target_os = "linux", target_env = "gnu"))] #[repr(u32)]
#[cfg(any(
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
target_os = "macos",
target_os = "ios",
target_os = "android",
target_os = "dragonfly",
target_os = "linux"))] #[repr(i32)]
RLIMIT_AS,
#[cfg(all(target_os = "linux", target_env = "gnu"))] #[repr(u32)]
#[cfg(any(
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
target_os = "macos",
target_os = "ios",
target_os = "android",
target_os = "dragonfly",
target_os = "linux"))] #[repr(i32)]
RLIMIT_CORE,
RLIMIT_CPU,
RLIMIT_DATA,
RLIMIT_FSIZE
}
} But this will have compile error for linux-musl series toolchain as both cfg will be compiled thus causing the compile error. The idea I have came out is using |
#[cfg_attr(any(target_os="linux", ...), repr(u32))]
#[cfg_attr(not(any(target_os="linux", ...), repr(u32)))] |
Thanks for given me suggestions. It is very helpful for. The new PR will be pushed out shortly. However, I have few doubts about the API of the current The existing api for pub fn getrlimit(resource: Resource) -> Result<(Option<rlim_t>, Option<rlim_t>)>;
pub fn setrlimit(resource: Resource, soft_limit: Option<rlim_t>, hard_limit: Option<rlim_t>) -> Result<()>; My current implementation is inherit from previous implementation, which treate The question I have is: should we treat I feel the later case is more natural for me. But it might be my personal preference. |
Also, I feel like the previous implementation does not have enough test. But I am not sure if it is necessary to test each flag(eg |
Looks like the test failure is a fake failure. Can we rerun it?
|
I agree that treating |
Hi @asomers. I think I have addressed your review comments. Please let me know if you feel like further improvements. Thank you. |
pub const RLIMIT_RSS: ::c_int = RLIMIT_AS;
Is it correct to select only one of them? |
@Nugine The reason why I select one of them is because they have the same value. If I select two of them, there will be a compile error like the following:
|
@asomers Do you have any further suggestions on the improvement? |
Eight months have passed. Is there any progress? |
I am happy to keep work on it. Just needs more inputs on the changes |
src/sys/resource.rs
Outdated
/// earier reference (non-exhaustive). | ||
/// | ||
/// * [Linux](https://man7.org/linux/man-pages/man2/getrlimit.2.html) | ||
/// * [freeBSD](https://www.freebsd.org/cgi/man.cgi?query=setrlimit) |
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.
The preferred spelling is "FreeBSD" (note the capital F)
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.
Thanks for the comments. Corrected :)
src/sys/resource.rs
Outdated
RLIMIT_NOFILE, | ||
RLIMIT_STACK, | ||
|
||
// platform specific |
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.
Why is this comment here? It seems like it should apply to every entry that has a #[cfg(...)]
. But #[cfg(...)]
is self-explanatory. Better just to leave it out.
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.
Removed
src/sys/resource.rs
Outdated
/// [`Resource`]: enum.Resource.html | ||
/// | ||
/// Note: `setrlimit` provides a safe wrapper to libc's `setrlimit`. For the | ||
/// platform that are not compatible, try using `prlimit` to set rlimit. |
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.
Is this comment obsolete now? prlimit is no longer included in the PR.
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.
Updated the obsolete comments.
test/test_resource.rs
Outdated
pub fn test_resource_limits_nofile() { | ||
let (soft_limit, hard_limit) = getrlimit(Resource::RLIMIT_NOFILE).unwrap(); | ||
|
||
// make sure the soft limit and hard limit are not equal |
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.
What ensures that the soft limit is not equal to the hard limit?
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.
This is actually obsolete comments from the very early version of the test, see LMJW@4f8b468
For this particular test, I believe we don't need to have soft limit to equal to hard limit
0fb6859
to
daa86d7
Compare
Hi @asomers. I have made some updates. Please let me know if you have any concerns. Thanks |
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.
Ok, it looks good. Just add a CHANGELOG entry and you'll be done.
Hi @asomers. I have updated the CHANGELOG. Thanks for reviewing the pull request :) |
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.
bors r+
When would the next release be that includes this change? Thanks. |
This PR is based on the previous PR #1190, which has not been updated for a very long time.
I have fixed the segfault and compilation error of the original PR and rebased the changes to the latest master branch.
Please let me know if anything need to been changed.