diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-03-24 18:03:00 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-06-02 10:05:02 +0200 |
| commit | c410f341152f752c686674d2ea51aac733f8fa97 (patch) | |
| tree | 7ea7157316f83e1fe2a1cb0fcd1d52f7a366f3a8 | |
| parent | 37e885e75b4ddce6bdaa5ffdcb5fa1557544231f (diff) | |
| download | mullvadvpn-c410f341152f752c686674d2ea51aac733f8fa97.tar.xz mullvadvpn-c410f341152f752c686674d2ea51aac733f8fa97.zip | |
Add function to add list of PIDs
| -rw-r--r-- | talpid-core/src/split.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/talpid-core/src/split.rs b/talpid-core/src/split.rs index 8973a6724c..8c9d4fa54a 100644 --- a/talpid-core/src/split.rs +++ b/talpid-core/src/split.rs @@ -316,16 +316,28 @@ impl PidManager { /// Add a PID to exclude from the tunnel. pub fn add(&self, pid: i32) -> Result<(), Error> { + self.add_list(&[pid]) + } + + /// Add PIDs to exclude from the tunnel. + pub fn add_list(&self, pids: &[i32]) -> Result<(), Error> { let exclusions_path = Path::new(NETCLS_DIR).join(CGROUP_NAME).join("cgroup.procs"); - let mut file = fs::OpenOptions::new() + let file = fs::OpenOptions::new() .write(true) .create(true) .open(exclusions_path) .map_err(Error::AddCGroupPid)?; - file.write_all(pid.to_string().as_bytes()) - .map_err(Error::AddCGroupPid) + let mut writer = BufWriter::new(file); + + for pid in pids { + writer + .write_all(pid.to_string().as_bytes()) + .map_err(Error::AddCGroupPid)?; + } + + Ok(()) } /// Remove a PID from processes to exclude from the tunnel. |
