fn handle_rlimit_nofile_option(args: &ArgMatches, option_name: &str) -> Result<()> {
    // `rlimit-nofile` has a default value, so safe to unwrap().
    let rlimit_nofile: rlim = args.value_of(option_name).unwrap().parse().map_err(|_e| {
        Error::new(
            ErrorKind::InvalidInput,
            "invalid value for option `rlimit-nofile`",
        )
    })?;

    if rlimit_nofile != 0 {
        // Ensures there are fds available for other processes so we don't cause resource exhaustion.
        let rlimit_nofile_max = get_max_rlimit_nofile()?;
        if rlimit_nofile_max < 2 * RLIMIT_NOFILE_RESERVED {
            return Err(eother!(
                "The fs.file-max sysctl is too low to allow a reasonable number of open files."
            ));
        }

        // Reduce max_fds below the system-wide maximum, if necessary.
        let rlimit_nofile_max = std::cmp::min(
            rlimit_nofile_max - RLIMIT_NOFILE_RESERVED,
            RLIMIT_NOFILE_MAX,
        );
        let rlimit_nofile_max = Resource::NOFILE.get().map(|(curr, _)| {
            if curr >= rlimit_nofile_max {
                curr
            } else {
                rlimit_nofile_max
            }
        })?;
        let rlimit_nofile = std::cmp::min(rlimit_nofile, rlimit_nofile_max);
        info!(
            "Set rlimit-nofile to {}, maximum {}",
            rlimit_nofile, rlimit_nofile_max
        );
        Resource::NOFILE.set(rlimit_nofile, rlimit_nofile)?;
    }

    Ok(())
}
/// Handle command line option to tune rlimit for maximum file descriptor number.
Handle command line option to tune rlimit for maximum file descriptor number.
Handle command line option to tune rlimit for maximum file descriptor number .
fn handle_rlimit_nofile_option(args: &ArgMatches, option_name: &str) -> Result<()> {
    // `rlimit-nofile` has a default value, so safe to unwrap().
    let rlimit_nofile: rlim = args.value_of(option_name).unwrap().parse().map_err(|_e| {
        Error::new(
            ErrorKind::InvalidInput,
            "invalid value for option `rlimit-nofile`",
        )
    })?;
    if rlimit_nofile != 0 {
        // Ensures there are fds available for other processes so we don't cause resource exhaustion.
        let rlimit_nofile_max = get_max_rlimit_nofile()?;
        if rlimit_nofile_max < 2 * RLIMIT_NOFILE_RESERVED {
            return Err(eother!(
                "The fs.file-max sysctl is too low to allow a reasonable number of open files."
            ));
        }
        // Reduce max_fds below the system-wide maximum, if necessary.
        let rlimit_nofile_max = std::cmp::min(
            rlimit_nofile_max - RLIMIT_NOFILE_RESERVED,
            RLIMIT_NOFILE_MAX,
        );
        let rlimit_nofile_max = Resource::NOFILE.get().map(|(curr, _)| {
            if curr >= rlimit_nofile_max {
                curr
            } else {
                rlimit_nofile_max
            }
        })?;
        let rlimit_nofile = std::cmp::min(rlimit_nofile, rlimit_nofile_max);
        info!(
            "Set rlimit-nofile to {}, maximum {}",
            rlimit_nofile, rlimit_nofile_max
        );
        Resource::NOFILE.set(rlimit_nofile, rlimit_nofile)?;
    }
    Ok(())
}
fn handle_rlimit_nofile_option ( args : & ArgMatches , option_name : & str ) -> Result < ( ) > { // `rlimit-nofile` has a default value, so safe to unwrap(). let rlimit_nofile : rlim = args . value_of ( option_name ) . unwrap ( ) . parse ( ) . map_err ( | _e | { Error :: new ( ErrorKind :: InvalidInput , " " , ) } ) ? ; if rlimit_nofile != 0 { // Ensures there are fds available for other processes so we don't cause resource exhaustion. let rlimit_nofile_max = get_max_rlimit_nofile ( ) ? ; if rlimit_nofile_max < 2 * RLIMIT_NOFILE_RESERVED { return Err ( eother ! ( " " ) ) ; } // Reduce max_fds below the system-wide maximum, if necessary. let rlimit_nofile_max = std :: cmp :: min ( rlimit_nofile_max - RLIMIT_NOFILE_RESERVED , RLIMIT_NOFILE_MAX , ) ; let rlimit_nofile_max = Resource :: NOFILE . get ( ) . map ( | ( curr , _ ) | { if curr >= rlimit_nofile_max { curr } else { rlimit_nofile_max } } ) ? ; let rlimit_nofile = std :: cmp :: min ( rlimit_nofile , rlimit_nofile_max ) ; info ! ( " " rlimit_nofile rlimit_nofile_max ) ; Resource :: NOFILE . set ( rlimit_nofile , rlimit_nofile ) ? ; } Ok ( ( ) ) }
Handle command line option to tune rlimit for maximum file descriptor number.
Handle command line option to tune rlimit for maximum file descriptor number .
args
&ArgMatches
option_name
&str
args
&ArgMatches
option_name
&str