mirror of
https://github.com/zhboner/realm.git
synced 2026-11-17 08:15:55 +00:00
syscall: bump nofile limit automatically
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "realm_syscall"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
authors = ["zephyr <i@zephyr.moe>"]
|
||||
description = "Realm's convenient syscall collections."
|
||||
repository = "https://github.com/zhboner/realm/realm_syscall"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::io::{Error, Result};
|
||||
use libc::{rlimit, rlim_t, RLIMIT_NOFILE};
|
||||
|
||||
/// Set nofile limitation.
|
||||
/// Set nofile limits.
|
||||
///
|
||||
/// `CAP_NET_ADMIN` privilege is required if exceeds hard limitation.
|
||||
///
|
||||
@@ -22,7 +22,7 @@ pub fn set_nofile_limit(nofile: u64) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get current nofile limitation.
|
||||
/// Get current nofile limits.
|
||||
///
|
||||
/// Reference: [man](https://man7.org/linux/man-pages/man2/setrlimit.2.html).
|
||||
#[cfg(all(unix, not(target_os = "android")))]
|
||||
@@ -38,3 +38,13 @@ pub fn get_nofile_limit() -> Result<(u64, u64)> {
|
||||
Ok((lim.rlim_cur as u64, lim.rlim_max as u64))
|
||||
}
|
||||
}
|
||||
|
||||
/// Bump nofile limits.
|
||||
#[cfg(all(unix, not(target_os = "android")))]
|
||||
pub fn bump_nofile_limit() -> Result<()> {
|
||||
let (cur, max) = get_nofile_limit()?;
|
||||
if cur != max {
|
||||
set_nofile_limit(cur)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user