Skip to content

Commit 88c0581

Browse files
committed
Commenting for clarity
1 parent b900fa0 commit 88c0581

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/sys/resource.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pub fn getrlimit(resource: Resource) -> Result<(Option<rlim_t>, Option<rlim_t>)>
134134
/// [`Resource`]: enum.Resource.html
135135
pub fn setrlimit(resource: Resource, soft_limit: Option<rlim_t>, hard_limit: Option<rlim_t>) -> Result<()> {
136136
let mut rlim: rlimit = unsafe { mem::uninitialized() };
137+
// TODO: How do we handle the case where soft_limit isn't Some()?
137138
rlim.rlim_cur = soft_limit.unwrap_or(RLIM_INFINITY);
138139
rlim.rlim_max = hard_limit.unwrap_or(RLIM_INFINITY);
139140

test/test_resource.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
use nix::sys::resource::{Resource, getrlimit, setrlimit};
22

3+
/// Tests the RLIMIT_NOFILE functionality of getrlimit(), where the resource RLIMIT_NOFILE refers
4+
/// to the maximum file descriptor number that can be opened by the process (aka the maximum number
5+
/// of file descriptors that the process can open, since Linux 4.5).
6+
///
7+
/// We first fetch the existing file descriptor maximum values using getrlimit(), then edit the
8+
/// soft limit to make sure it has a new and distinct value to the hard limit. We then setrlimit()
9+
/// to put the new soft limit in effect, and then getrlimit() once more to ensure the limits have
10+
/// been updated.
311
#[test]
412
pub fn test_resource_limits_nofile() {
513
let (soft_limit, hard_limit) = getrlimit(Resource::RLIMIT_NOFILE).unwrap();
@@ -15,6 +23,12 @@ pub fn test_resource_limits_nofile() {
1523
assert_eq!(new_soft_limit, soft_limit);
1624
}
1725

26+
/// Tests the RLIMIT_STACK functionality of getrlimit(), where the resource RLIMIT_STACK refers to
27+
/// the maximum stack size that can be spawned by the current process before SIGSEGV is generated.
28+
///
29+
/// We first save the current stack limits, then newly set the soft limit to the same size as the
30+
/// hard limit. We check to make sure these limits have been updated properly. We then set the
31+
/// stack limits back to the original values, and make sure they have been updated properly.
1832
#[test]
1933
pub fn test_resource_limits_stack() {
2034
let (mut soft_limit, hard_limit) = getrlimit(Resource::RLIMIT_STACK).unwrap();

0 commit comments

Comments
 (0)