diff options
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 45 | ||||
| -rw-r--r-- | mullvad-daemon/src/macos.rs (renamed from mullvad-daemon/src/exclusion_gid.rs) | 37 |
2 files changed, 41 insertions, 41 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 79c4e5cff1..d950f20663 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -11,10 +11,10 @@ mod cleanup; pub mod device; mod dns; pub mod exception_logging; -#[cfg(target_os = "macos")] -pub mod exclusion_gid; mod geoip; pub mod logging; +#[cfg(target_os = "macos")] +mod macos; #[cfg(not(target_os = "android"))] pub mod management_interface; mod migrations; @@ -544,8 +544,8 @@ where ) -> Result<Self, Error> { #[cfg(target_os = "macos")] let exclusion_gid = { - bump_filehandle_limit(); - exclusion_gid::set_exclusion_gid().map_err(Error::GroupIdError)? + macos::bump_filehandle_limit(); + macos::set_exclusion_gid().map_err(Error::GroupIdError)? }; mullvad_api::proxy::ApiConnectionMode::try_delete_cache(&cache_dir).await; @@ -2176,40 +2176,3 @@ fn new_selector_config(settings: &Settings) -> SelectorConfig { obfuscation_settings: settings.obfuscation_settings.clone(), } } - -/// Bump filehandle limit -#[cfg(target_os = "macos")] -pub fn bump_filehandle_limit() { - let mut limits = libc::rlimit { - rlim_cur: 0, - rlim_max: 0, - }; - // SAFETY: `&mut limits` is a valid pointer parameter for the getrlimit syscall - let status = unsafe { libc::getrlimit(libc::RLIMIT_NOFILE, &mut limits) }; - if status != 0 { - log::error!( - "Failed to get file handle limits: {}-{}", - io::Error::from_raw_os_error(status), - status - ); - return; - } - - const INCREASED_FILEHANDLE_LIMIT: u64 = 1024; - // 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; - // SAFETY: `&limits` is a valid pointer parameter for the getrlimit syscall - let status = unsafe { libc::setrlimit(libc::RLIMIT_NOFILE, &limits) }; - if status != 0 { - log::error!( - "Failed to set file handle limit to {}: {}-{}", - INCREASED_FILEHANDLE_LIMIT, - io::Error::from_raw_os_error(status), - status - ); - } -} diff --git a/mullvad-daemon/src/exclusion_gid.rs b/mullvad-daemon/src/macos.rs index ec87c5a7c6..24511fe337 100644 --- a/mullvad-daemon/src/exclusion_gid.rs +++ b/mullvad-daemon/src/macos.rs @@ -1,7 +1,44 @@ use std::{ffi::CStr, io}; + /// name of the group that should be excluded const EXCLUSION_GROUP: &[u8] = b"mullvad-exclusion\0"; +/// Bump filehandle limit +pub fn bump_filehandle_limit() { + let mut limits = libc::rlimit { + rlim_cur: 0, + rlim_max: 0, + }; + // SAFETY: `&mut limits` is a valid pointer parameter for the getrlimit syscall + let status = unsafe { libc::getrlimit(libc::RLIMIT_NOFILE, &mut limits) }; + if status != 0 { + log::error!( + "Failed to get file handle limits: {}-{}", + io::Error::from_raw_os_error(status), + status + ); + return; + } + + const INCREASED_FILEHANDLE_LIMIT: u64 = 1024; + // 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; + // SAFETY: `&limits` is a valid pointer parameter for the getrlimit syscall + let status = unsafe { libc::setrlimit(libc::RLIMIT_NOFILE, &limits) }; + if status != 0 { + log::error!( + "Failed to set file handle limit to {}: {}-{}", + INCREASED_FILEHANDLE_LIMIT, + io::Error::from_raw_os_error(status), + status + ); + } +} + /// Returns the GID of `mullvad-exclusion` group if it exists. pub fn get_exclusion_gid() -> io::Result<u32> { let exclusion_group_name = CStr::from_bytes_with_nul(EXCLUSION_GROUP).unwrap(); |
