mirror of
https://github.com/openai/codex.git
synced 2026-10-20 17:38:45 +00:00
## What changed For managed app-server daemons using Unix sockets, raise the soft `RLIMIT_NOFILE` limit to 4096 at startup, capped by the inherited hard limit. Preserve existing higher soft limits and log a warning if the adjustment fails. GitOrigin-RevId: 2ef27370e55cd86a7a62cbc3d47041933b89ac21
27 lines
855 B
Rust
27 lines
855 B
Rust
//! Unix process setup specific to a managed app-server daemon.
|
|
|
|
use std::io;
|
|
|
|
const NOFILE_LIMIT: libc::rlim_t = 4096;
|
|
|
|
pub(crate) fn raise_nofile_limit() -> io::Result<()> {
|
|
let mut limit = libc::rlimit {
|
|
rlim_cur: 0,
|
|
rlim_max: 0,
|
|
};
|
|
// SAFETY: getrlimit initializes the stack-owned resource-limit structure.
|
|
if unsafe { libc::getrlimit(libc::RLIMIT_NOFILE, &raw mut limit) } == -1 {
|
|
return Err(io::Error::last_os_error());
|
|
}
|
|
let target = limit.rlim_cur.max(limit.rlim_max.min(NOFILE_LIMIT));
|
|
if target == limit.rlim_cur {
|
|
return Ok(());
|
|
}
|
|
limit.rlim_cur = target;
|
|
// SAFETY: the requested soft limit does not exceed the inherited hard limit.
|
|
if unsafe { libc::setrlimit(libc::RLIMIT_NOFILE, &limit) } == -1 {
|
|
return Err(io::Error::last_os_error());
|
|
}
|
|
Ok(())
|
|
}
|