diff --git a/Cargo.lock b/Cargo.lock index 1b5b6192ecf0..6ba669fe5e8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1853,7 +1853,6 @@ dependencies = [ "nix 0.23.2", "objc", "once_cell", - "parking_lot", "regex", "serde", "serde_json", diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml index 0198ae1a15e7..aaa893e170b3 100644 --- a/mullvad-daemon/Cargo.toml +++ b/mullvad-daemon/Cargo.toml @@ -20,7 +20,6 @@ futures = "0.3" once_cell = "1.13" libc = "0.2" log = { workspace = true } -parking_lot = "0.12.0" regex = "1.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index 76b6a7e4fd35..23f2578f5899 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -23,12 +23,11 @@ use mullvad_types::{ version, wireguard::{RotationInterval, RotationIntervalError}, }; -use parking_lot::RwLock; #[cfg(windows)] use std::path::PathBuf; use std::{ convert::{TryFrom, TryInto}, - sync::Arc, + sync::{Arc, Mutex}, time::Duration, }; use talpid_types::ErrorExt; @@ -44,7 +43,7 @@ pub enum Error { struct ManagementServiceImpl { daemon_tx: DaemonCommandSender, - subscriptions: Arc>>, + subscriptions: Arc>>, } pub type ServiceResult = std::result::Result, Status>; @@ -102,7 +101,7 @@ impl ManagementService for ManagementServiceImpl { async fn events_listen(&self, _: Request<()>) -> ServiceResult { let (tx, rx) = tokio::sync::mpsc::unbounded_channel(); - let mut subscriptions = self.subscriptions.write(); + let mut subscriptions = self.subscriptions.lock().unwrap(); subscriptions.push(tx); Ok(Response::new(UnboundedReceiverStream::new(rx))) @@ -881,7 +880,7 @@ impl ManagementInterfaceServer { pub fn start( tunnel_tx: DaemonCommandSender, ) -> Result<(String, ManagementInterfaceEventBroadcaster), Error> { - let subscriptions = Arc::>>::default(); + let subscriptions = Arc::>>::default(); let socket_path = mullvad_paths::get_rpc_socket_path() .to_string_lossy() @@ -917,7 +916,7 @@ impl ManagementInterfaceServer { /// A handle that allows broadcasting messages to all subscribers of the management interface. #[derive(Clone)] pub struct ManagementInterfaceEventBroadcaster { - subscriptions: Arc>>, + subscriptions: Arc>>, _close_handle: mpsc::Sender<()>, } @@ -981,8 +980,7 @@ impl EventListener for ManagementInterfaceEventBroadcaster { impl ManagementInterfaceEventBroadcaster { fn notify(&self, value: types::DaemonEvent) { - let mut subscriptions = self.subscriptions.write(); - // TODO: using write-lock everywhere. use a mutex instead? + let mut subscriptions = self.subscriptions.lock().unwrap(); subscriptions.retain(|tx| tx.send(Ok(value.clone())).is_ok()); } } diff --git a/mullvad-daemon/src/migrations/mod.rs b/mullvad-daemon/src/migrations/mod.rs index 69d384956c24..8624677f069b 100644 --- a/mullvad-daemon/src/migrations/mod.rs +++ b/mullvad-daemon/src/migrations/mod.rs @@ -369,8 +369,6 @@ mod windows { pub fn owner(&self) -> Option<&SID> { unsafe { (self.owner as *const SID).as_ref() } } - - // TODO: Can be expanded with `group()`, `dacl()`, and `sacl()`. } impl Drop for SecurityInformation { diff --git a/talpid-core/src/dns/windows/iphlpapi.rs b/talpid-core/src/dns/windows/iphlpapi.rs index 9fe4b3bfc4ef..2d62e1860e19 100644 --- a/talpid-core/src/dns/windows/iphlpapi.rs +++ b/talpid-core/src/dns/windows/iphlpapi.rs @@ -81,7 +81,8 @@ impl IphlpApi { } // This function is loaded at runtime since it may be unavailable. See the module-level docs. - // TODO: `windows_sys` can be used directly when support for Windows 10, 2004, is dropped. + // TODO: `windows_sys` can be used directly when support for versions older than Windows 10, + // 2004, is dropped. let set_interface_dns_settings = unsafe { GetProcAddress(module, s!("SetInterfaceDnsSettings")) }; let set_interface_dns_settings = set_interface_dns_settings.ok_or_else(|| { diff --git a/talpid-core/src/split_tunnel/linux.rs b/talpid-core/src/split_tunnel/linux.rs index 2ba63dda9e51..67d671d13cbf 100644 --- a/talpid-core/src/split_tunnel/linux.rs +++ b/talpid-core/src/split_tunnel/linux.rs @@ -125,12 +125,8 @@ impl PidManager { pub fn remove(&self, pid: i32) -> Result<(), Error> { // FIXME: We remove PIDs from our cgroup here by adding // them to the parent cgroup. This seems wrong. - let exclusions_path = self.net_cls_path.join("cgroup.procs"); - - let mut file = fs::OpenOptions::new() - .write(true) - .create(true) - .open(exclusions_path) + let mut file = self + .open_parent_cgroup_handle() .map_err(Error::RemoveCGroupPid)?; file.write_all(pid.to_string().as_bytes()) @@ -160,13 +156,23 @@ impl PidManager { /// Removes all PIDs from the Cgroup. pub fn clear(&self) -> Result<(), Error> { - // TODO: reuse file handle let pids = self.list()?; + let mut file = self + .open_parent_cgroup_handle() + .map_err(Error::RemoveCGroupPid)?; for pid in pids { - self.remove(pid)?; + file.write_all(pid.to_string().as_bytes()) + .map_err(Error::RemoveCGroupPid)?; } Ok(()) } + + fn open_parent_cgroup_handle(&self) -> io::Result { + fs::OpenOptions::new() + .write(true) + .create(true) + .open(self.net_cls_path.join("cgroup.procs")) + } }