1
1
use nix:: sys:: resource:: { Resource , getrlimit, setrlimit} ;
2
2
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.
3
11
#[ test]
4
12
pub fn test_resource_limits_nofile ( ) {
5
13
let ( soft_limit, hard_limit) = getrlimit ( Resource :: RLIMIT_NOFILE ) . unwrap ( ) ;
@@ -15,6 +23,12 @@ pub fn test_resource_limits_nofile() {
15
23
assert_eq ! ( new_soft_limit, soft_limit) ;
16
24
}
17
25
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.
18
32
#[ test]
19
33
pub fn test_resource_limits_stack ( ) {
20
34
let ( mut soft_limit, hard_limit) = getrlimit ( Resource :: RLIMIT_STACK ) . unwrap ( ) ;
0 commit comments