diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-02-26 15:25:28 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-06-02 10:05:01 +0200 |
| commit | f4f5f6ebf8b75abe17556fc172156756331b4040 (patch) | |
| tree | e388844e3ae4a1aa0c0f729dde4bb5085c0e4ae0 /talpid-core/src | |
| parent | 25e9ec1a0a971e6e2e9ab4e592c48b13fbffa985 (diff) | |
| download | mullvadvpn-f4f5f6ebf8b75abe17556fc172156756331b4040.tar.xz mullvadvpn-f4f5f6ebf8b75abe17556fc172156756331b4040.zip | |
Add function that lists PIDs in cgroup
Diffstat (limited to 'talpid-core/src')
| -rw-r--r-- | talpid-core/src/split.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/talpid-core/src/split.rs b/talpid-core/src/split.rs index b95caaf7f8..6856edb790 100644 --- a/talpid-core/src/split.rs +++ b/talpid-core/src/split.rs @@ -1,6 +1,6 @@ use std::{ fs, - io::{self, Write}, + io::{self, BufRead, BufReader, Write}, path::Path, }; @@ -24,6 +24,10 @@ pub enum Error { /// Unable to add PID to cgroup.procs. #[error(display = "Unable to add PID to cgroup.procs")] AddCGroupPid(#[error(source)] io::Error), + + /// Unable to read cgroup.procs. + #[error(display = "Unable to obtain PIDs from cgroup.procs")] + ListCGroupPids(#[error(source)] io::Error), } /// Set up cgroup used to track PIDs for split tunneling. @@ -51,3 +55,21 @@ pub fn add_pid(pid: i32) -> Result<(), Error> { file.write_all(pid.to_string().as_bytes()) .map_err(Error::AddCGroupPid) } + +/// Return a list of PIDs that are excluded from the tunnel. +pub fn list_pids() -> Result<Vec<i32>, Error> { + let exclusions_path = Path::new(NETCLS_DIR).join(CGROUP_NAME).join("cgroup.procs"); + + let file = fs::File::open(exclusions_path).map_err(Error::ListCGroupPids)?; + + let result: Result<Vec<i32>, io::Error> = BufReader::new(file) + .lines() + .map(|line| { + line.and_then(|v| { + v.parse() + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) + }) + }) + .collect(); + result.map_err(Error::ListCGroupPids) +} |
