From e000e9168384e9472111df6622ed66d4ba46151c Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 2 Apr 2023 06:33:32 -0700 Subject: [PATCH] maybe fix freebsd build rlim_t is signed on that platform, so take care to convert to appease the compiler. --- config/src/config.rs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/config/src/config.rs b/config/src/config.rs index de5d66a50..f45676749 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -831,20 +831,28 @@ impl Config { pub fn update_ulimit(&self) -> anyhow::Result<()> { #[cfg(unix)] { - use nix::sys::resource::{getrlimit, setrlimit, Resource}; + use nix::sys::resource::{getrlimit, rlim_t, setrlimit, Resource}; + use std::convert::TryInto; let (no_file_soft, no_file_hard) = getrlimit(Resource::RLIMIT_NOFILE)?; - if no_file_soft < self.ulimit_nofile { + let ulimit_nofile: rlim_t = self.ulimit_nofile.try_into().with_context(|| { + format!( + "ulimit_nofile value {} is out of range for this system", + self.ulimit_nofile + ) + })?; + + if no_file_soft < ulimit_nofile { setrlimit( Resource::RLIMIT_NOFILE, - self.ulimit_nofile.min(no_file_hard), + ulimit_nofile.min(no_file_hard), no_file_hard, ) .with_context(|| { format!( "raise RLIMIT_NOFILE from {no_file_soft} to ulimit_nofile {}", - self.ulimit_nofile + ulimit_nofile ) })?; } @@ -852,20 +860,28 @@ impl Config { #[cfg(all(unix, not(target_os = "macos")))] { - use nix::sys::resource::{getrlimit, setrlimit, Resource}; + use nix::sys::resource::{getrlimit, rlim_t, setrlimit, Resource}; + use std::convert::TryInto; let (nproc_soft, nproc_hard) = getrlimit(Resource::RLIMIT_NPROC)?; - if nproc_soft < self.ulimit_nproc { + let ulimit_nproc: rlim_t = self.ulimit_nproc.try_into().with_context(|| { + format!( + "ulimit_nproc value {} is out of range for this system", + self.ulimit_nproc + ) + })?; + + if nproc_soft < ulimit_nproc { setrlimit( Resource::RLIMIT_NPROC, - self.ulimit_nproc.min(nproc_hard), + ulimit_nproc.min(nproc_hard), nproc_hard, ) .with_context(|| { format!( "raise RLIMIT_NPROC from {nproc_soft} to ulimit_nproc {}", - self.ulimit_nproc + ulimit_nproc ) })?; }