Skip to content

nix::sys::resource::getrlimit doesn't actually return None #1666

Closed
@Arnavion

Description

@Arnavion

Documentation says:

nix/src/sys/resource.rs

Lines 176 to 177 in 6123083

/// A value of `None` indicates the value equals to `RLIM_INFINITY` which means
/// there is no limit.

but code unconditionally returns Some():

nix/src/sys/resource.rs

Lines 209 to 212 in 6123083

Errno::result(res).map(|_| {
let rlimit { rlim_cur, rlim_max } = unsafe { old_rlim.assume_init() };
(Some(rlim_cur), Some(rlim_max))
})

This documentation is leftover from the old PR code which did return None:

    Errno::result(res).map(|_| {
        (if rlim.rlim_cur != RLIM_INFINITY { Some(rlim.rlim_cur) } else { None },
         if rlim.rlim_max != RLIM_INFINITY { Some(rlim.rlim_max) } else { None })
    })

... but the new PR removed that branch.

It would be nice to not return Option from getrlimit at least, since it makes the caller code more annoying when we only want to call setrlimit when we need to, which requires comparing the returned soft limit vs the returned hard limit. And if getrlimit is changed to not special-case INFINITY, the special-case might as well be removed from setrlimit too so that one doesn't need to Some()-wrap the values when passing them from getrlimit to setrlimit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions