syscall: bump nofile limit automatically

This commit is contained in:
zephyr
2022-08-28 23:48:08 +09:00
parent c07e88ee4e
commit d2c1e1c457
2 changed files with 13 additions and 3 deletions
+1 -1
View File
@@ -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"
+12 -2
View File
@@ -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(())
}