1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 13:21:38 +03:00

maybe fix freebsd build

rlim_t is signed on that platform, so take care to convert
to appease the compiler.
This commit is contained in:
Wez Furlong 2023-04-02 06:33:32 -07:00
parent 000269261b
commit e000e91683
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387

View File

@ -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
)
})?;
}