summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmīls <emils@mullvad.net>2021-11-16 18:36:12 +0000
committerEmīls <emils@mullvad.net>2021-12-10 09:58:51 +0000
commit8710dab536c9e8007ca6a35418883a2ea45d43ab (patch)
treeed5acc828d17830490d669ae8e38cff8657684de
parent51dbbc605c99874d955e3ada33854c6ec97ab43c (diff)
downloadmullvadvpn-8710dab536c9e8007ca6a35418883a2ea45d43ab.tar.xz
mullvadvpn-8710dab536c9e8007ca6a35418883a2ea45d43ab.zip
Bump file handle limit
-rw-r--r--mullvad-daemon/src/lib.rs1
-rw-r--r--talpid-core/src/macos.rs37
2 files changed, 37 insertions, 1 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index bbd903577f..5410ee569e 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -568,6 +568,7 @@ where
#[cfg(target_os = "macos")]
{
exclusion_gid::set_exclusion_gid();
+ talpid_core::macos::bump_filehandle_limit();
};
let (tunnel_state_machine_shutdown_tx, tunnel_state_machine_shutdown_signal) =
diff --git a/talpid-core/src/macos.rs b/talpid-core/src/macos.rs
index d1f6a727a5..0b102e4dd7 100644
--- a/talpid-core/src/macos.rs
+++ b/talpid-core/src/macos.rs
@@ -1,4 +1,4 @@
-use std::ffi::CStr;
+use std::{ffi::CStr, io};
/// Returns the GID of `mullvad-exclusion` group if it exists.
pub fn get_group_id(group_name: &CStr) -> Option<u32> {
@@ -9,3 +9,38 @@ pub fn get_group_id(group_name: &CStr) -> Option<u32> {
let gid = unsafe { (*group).gr_gid };
Some(gid)
}
+
+
+const INCREASED_FILEHANDLE_LIMIT: u64 = 1024;
+/// Bump filehandle limit
+pub fn bump_filehandle_limit() {
+ let mut limits = libc::rlimit {
+ rlim_cur: 0,
+ rlim_max: 0,
+ };
+ let status = unsafe { libc::getrlimit(libc::RLIMIT_NOFILE, &mut limits as *mut _) };
+ if status != 0 {
+ log::error!(
+ "Failed to get file handle limits: {}-{}",
+ io::Error::from_raw_os_error(status),
+ status
+ );
+ return;
+ }
+
+ // if file handle limit is already big enough, there's no reason to decrease it.
+ if limits.rlim_cur >= INCREASED_FILEHANDLE_LIMIT {
+ return;
+ }
+
+ limits.rlim_cur = INCREASED_FILEHANDLE_LIMIT;
+ let status = unsafe { libc::setrlimit(libc::RLIMIT_NOFILE, &limits as *const _) };
+ if status != 0 {
+ log::error!(
+ "Failed to set file handle limit to {}: {}-{}",
+ INCREASED_FILEHANDLE_LIMIT,
+ io::Error::from_raw_os_error(status),
+ status
+ );
+ }
+}