From 88c05815025bc9e3449b0b080ceeae995e182621 Mon Sep 17 00:00:00 2001 From: Jiahong Long Date: Thu, 5 Mar 2020 17:58:01 -0800 Subject: [PATCH] Commenting for clarity --- src/sys/resource.rs | 1 + test/test_resource.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/sys/resource.rs b/src/sys/resource.rs index 7f8fa507d9..941ff26bcd 100644 --- a/src/sys/resource.rs +++ b/src/sys/resource.rs @@ -134,6 +134,7 @@ pub fn getrlimit(resource: Resource) -> Result<(Option, Option)> /// [`Resource`]: enum.Resource.html pub fn setrlimit(resource: Resource, soft_limit: Option, hard_limit: Option) -> Result<()> { let mut rlim: rlimit = unsafe { mem::uninitialized() }; + // TODO: How do we handle the case where soft_limit isn't Some()? rlim.rlim_cur = soft_limit.unwrap_or(RLIM_INFINITY); rlim.rlim_max = hard_limit.unwrap_or(RLIM_INFINITY); diff --git a/test/test_resource.rs b/test/test_resource.rs index 4735d0a380..0e189b123b 100644 --- a/test/test_resource.rs +++ b/test/test_resource.rs @@ -1,5 +1,13 @@ use nix::sys::resource::{Resource, getrlimit, setrlimit}; +/// Tests the RLIMIT_NOFILE functionality of getrlimit(), where the resource RLIMIT_NOFILE refers +/// to the maximum file descriptor number that can be opened by the process (aka the maximum number +/// of file descriptors that the process can open, since Linux 4.5). +/// +/// We first fetch the existing file descriptor maximum values using getrlimit(), then edit the +/// soft limit to make sure it has a new and distinct value to the hard limit. We then setrlimit() +/// to put the new soft limit in effect, and then getrlimit() once more to ensure the limits have +/// been updated. #[test] pub fn test_resource_limits_nofile() { let (soft_limit, hard_limit) = getrlimit(Resource::RLIMIT_NOFILE).unwrap(); @@ -15,6 +23,12 @@ pub fn test_resource_limits_nofile() { assert_eq!(new_soft_limit, soft_limit); } +/// Tests the RLIMIT_STACK functionality of getrlimit(), where the resource RLIMIT_STACK refers to +/// the maximum stack size that can be spawned by the current process before SIGSEGV is generated. +/// +/// We first save the current stack limits, then newly set the soft limit to the same size as the +/// hard limit. We check to make sure these limits have been updated properly. We then set the +/// stack limits back to the original values, and make sure they have been updated properly. #[test] pub fn test_resource_limits_stack() { let (mut soft_limit, hard_limit) = getrlimit(Resource::RLIMIT_STACK).unwrap();