diff options
| author | Emīls <emils@mullvad.net> | 2020-06-05 19:19:17 +0100 |
|---|---|---|
| committer | Emīls <emils@mullvad.net> | 2020-06-05 19:44:12 +0100 |
| commit | 73b4d019e8e6b1b5fad3e74fefbf723e5e569cc8 (patch) | |
| tree | c4b5ca074aba281f66c7b65710f81fe6a880005c | |
| parent | 9f24024e55c166f0b84cfadbb8f856baa2203193 (diff) | |
| download | mullvadvpn-73b4d019e8e6b1b5fad3e74fefbf723e5e569cc8.tar.xz mullvadvpn-73b4d019e8e6b1b5fad3e74fefbf723e5e569cc8.zip | |
Improve mullvad-exclude
`mullvad-exclude` seems to fail on NixOS with a permissions error when
trying to open /sys/fs/cgroup/net_cls/mullvad-exclude/cgroup.procs. I
noticed that the daemon did not have such issues, so I presumed it's the
options with which the procs file is opened with that are to blame. As
such, I've set the changed the code to use the same options in
`mullvad-exclude` as in `talpid-core`.
| -rw-r--r-- | mullvad-exclude/src/main.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/mullvad-exclude/src/main.rs b/mullvad-exclude/src/main.rs index cfa180532a..4aa8fea4dc 100644 --- a/mullvad-exclude/src/main.rs +++ b/mullvad-exclude/src/main.rs @@ -5,7 +5,8 @@ use std::{ env, error::Error as StdError, ffi::{CStr, CString, NulError}, - fs, io, + fs, + io::{self, BufWriter, Write}, os::unix::ffi::OsStrExt, path::Path, }; @@ -82,7 +83,16 @@ fn run() -> Result<void::Void, Error> { // Set the cgroup of this process let cgroup_dir = Path::new(NETCLS_DIR).join(SPLIT_TUNNEL_CGROUP_NAME); let procs_path = cgroup_dir.join("cgroup.procs"); - fs::write(procs_path, getpid().to_string().as_bytes()).map_err(Error::AddProcToCGroup)?; + + let file = fs::OpenOptions::new() + .write(true) + .create(true) + .open(procs_path) + .map_err(Error::AddProcToCGroup)?; + + BufWriter::new(file) + .write_all(getpid().to_string().as_bytes()) + .map_err(Error::AddProcToCGroup)?; // Drop root privileges let real_uid = getuid(); |
