diff options
| author | David Lönnhager <david.l@mullvad.net> | 2023-09-08 15:35:13 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2023-09-11 16:40:37 +0200 |
| commit | ee0e6700d7260a20b95859677c199dd83ae3f718 (patch) | |
| tree | 1f53cef85e8b913e8280626ff95cda984a1741d3 | |
| parent | 8452b97d4e9545f2574ebbd9c7545ff76189a9ed (diff) | |
| download | mullvadvpn-ee0e6700d7260a20b95859677c199dd83ae3f718.tar.xz mullvadvpn-ee0e6700d7260a20b95859677c199dd83ae3f718.zip | |
Remove pointless open() calls
| -rw-r--r-- | talpid-core/src/split_tunnel/linux.rs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/talpid-core/src/split_tunnel/linux.rs b/talpid-core/src/split_tunnel/linux.rs index 2ba63dda9e..67d671d13c 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::File> { + fs::OpenOptions::new() + .write(true) + .create(true) + .open(self.net_cls_path.join("cgroup.procs")) + } } |
