@@ -8,7 +8,7 @@ use std::mem;
8
8
9
9
cfg_if ! {
10
10
if #[ cfg( all( target_os = "linux" , any( target_env = "gnu" , target_env = "uclibc" ) ) ) ] {
11
- use libc:: { __rlimit_resource_t, rlimit, RLIM_INFINITY } ;
11
+ use libc:: { __rlimit_resource_t, rlimit} ;
12
12
} else if #[ cfg( any(
13
13
target_os = "freebsd" ,
14
14
target_os = "openbsd" ,
@@ -19,7 +19,7 @@ cfg_if! {
19
19
target_os = "dragonfly" ,
20
20
all( target_os = "linux" , not( target_env = "gnu" ) )
21
21
) ) ] {
22
- use libc:: { c_int, rlimit, RLIM_INFINITY } ;
22
+ use libc:: { c_int, rlimit} ;
23
23
}
24
24
}
25
25
@@ -173,8 +173,8 @@ libc_enum! {
173
173
174
174
/// Get the current processes resource limits
175
175
///
176
- /// A value of `None ` indicates the value equals to `RLIM_INFINITY` which means
177
- /// there is no limit .
176
+ /// The special value `RLIM_INFINITY ` indicates that no limit will be
177
+ /// enforced .
178
178
///
179
179
/// # Parameters
180
180
///
@@ -186,16 +186,16 @@ libc_enum! {
186
186
/// # use nix::sys::resource::{getrlimit, Resource};
187
187
///
188
188
/// let (soft_limit, hard_limit) = getrlimit(Resource::RLIMIT_NOFILE).unwrap();
189
- /// println!("current soft_limit: {:? }", soft_limit);
190
- /// println!("current hard_limit: {:? }", hard_limit);
189
+ /// println!("current soft_limit: {}", soft_limit);
190
+ /// println!("current hard_limit: {}", hard_limit);
191
191
/// ```
192
192
///
193
193
/// # References
194
194
///
195
195
/// [getrlimit(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/getrlimit.html#tag_16_215)
196
196
///
197
197
/// [`Resource`]: enum.Resource.html
198
- pub fn getrlimit ( resource : Resource ) -> Result < ( Option < rlim_t > , Option < rlim_t > ) > {
198
+ pub fn getrlimit ( resource : Resource ) -> Result < ( rlim_t , rlim_t ) > {
199
199
let mut old_rlim = mem:: MaybeUninit :: < rlimit > :: uninit ( ) ;
200
200
201
201
cfg_if ! {
@@ -208,7 +208,7 @@ pub fn getrlimit(resource: Resource) -> Result<(Option<rlim_t>, Option<rlim_t>)>
208
208
209
209
Errno :: result ( res) . map ( |_| {
210
210
let rlimit { rlim_cur, rlim_max } = unsafe { old_rlim. assume_init ( ) } ;
211
- ( Some ( rlim_cur) , Some ( rlim_max) )
211
+ ( rlim_cur, rlim_max)
212
212
} )
213
213
}
214
214
@@ -218,21 +218,20 @@ pub fn getrlimit(resource: Resource) -> Result<(Option<rlim_t>, Option<rlim_t>)>
218
218
///
219
219
/// * `resource`: The [`Resource`] that we want to set the limits of.
220
220
/// * `soft_limit`: The value that the kernel enforces for the corresponding
221
- /// resource. Note: `None` input will be replaced by constant `RLIM_INFINITY`.
221
+ /// resource.
222
222
/// * `hard_limit`: The ceiling for the soft limit. Must be lower or equal to
223
- /// the current hard limit for non-root users. Note: `None` input will be
224
- /// replaced by constant `RLIM_INFINITY`.
223
+ /// the current hard limit for non-root users.
225
224
///
226
- /// > Note: for some os (linux_gnu), setting hard_limit to `RLIM_INFINITY` can
227
- /// > results `EPERM` Error. So you will need to set the number explicitly .
225
+ /// The special value `RLIM_INFINITY` indicates that no limit will be
226
+ /// enforced .
228
227
///
229
228
/// # Examples
230
229
///
231
230
/// ```
232
231
/// # use nix::sys::resource::{setrlimit, Resource};
233
232
///
234
- /// let soft_limit = Some( 512) ;
235
- /// let hard_limit = Some( 1024) ;
233
+ /// let soft_limit = 512;
234
+ /// let hard_limit = 1024;
236
235
/// setrlimit(Resource::RLIMIT_NOFILE, soft_limit, hard_limit).unwrap();
237
236
/// ```
238
237
///
@@ -245,12 +244,12 @@ pub fn getrlimit(resource: Resource) -> Result<(Option<rlim_t>, Option<rlim_t>)>
245
244
/// Note: `setrlimit` provides a safe wrapper to libc's `setrlimit`.
246
245
pub fn setrlimit (
247
246
resource : Resource ,
248
- soft_limit : Option < rlim_t > ,
249
- hard_limit : Option < rlim_t > ,
247
+ soft_limit : rlim_t ,
248
+ hard_limit : rlim_t ,
250
249
) -> Result < ( ) > {
251
250
let new_rlim = rlimit {
252
- rlim_cur : soft_limit. unwrap_or ( RLIM_INFINITY ) ,
253
- rlim_max : hard_limit. unwrap_or ( RLIM_INFINITY ) ,
251
+ rlim_cur : soft_limit,
252
+ rlim_max : hard_limit,
254
253
} ;
255
254
cfg_if ! {
256
255
if #[ cfg( all( target_os = "linux" , any( target_env = "gnu" , target_env = "uclibc" ) ) ) ] {
0 commit comments