diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-01-12 09:48:44 +0100 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-01-12 09:55:13 +0100 |
| commit | 35e666b1cb4bfe5d61f4da4813bbfe4c1868ef08 (patch) | |
| tree | 5439b5e160d5eb1cd660a4c83084dc72d0936ac6 /src/process | |
| parent | 7cf592b33fe4cb377694e9f9ec3230b73273013c (diff) | |
| download | mullvadvpn-35e666b1cb4bfe5d61f4da4813bbfe4c1868ef08.tar.xz mullvadvpn-35e666b1cb4bfe5d61f4da4813bbfe4c1868ef08.zip | |
Standard streams can be discarded
Diffstat (limited to 'src/process')
| -rw-r--r-- | src/process/mod.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/process/mod.rs b/src/process/mod.rs index 0538eb8c62..e469ce7b58 100644 --- a/src/process/mod.rs +++ b/src/process/mod.rs @@ -19,6 +19,7 @@ pub struct OpenVpnCommand { openvpn_bin: OsString, config: Option<PathBuf>, remotes: Vec<RemoteAddr>, + forward_standard_streams: bool, } impl OpenVpnCommand { @@ -29,6 +30,7 @@ impl OpenVpnCommand { openvpn_bin: OsString::from(openvpn_bin.as_ref()), config: None, remotes: vec![], + forward_standard_streams: true, } } @@ -45,6 +47,12 @@ impl OpenVpnCommand { Ok(self) } + /// Invoke this to not create stdout and stderr streams for the subprocess + pub fn discard_standard_streams(&mut self) -> &mut Self { + self.forward_standard_streams = false; + self + } + /// Executes the OpenVPN process as a child process, returning a handle to it. pub fn spawn(&self) -> io::Result<Child> { let mut command = self.create_command(); @@ -56,11 +64,19 @@ impl OpenVpnCommand { let mut command = Command::new(&self.openvpn_bin); command.env_clear() .stdin(Stdio::null()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()); + .stdout(self.get_std_streams_forward_policy()) + .stderr(self.get_std_streams_forward_policy()); command } + fn get_std_streams_forward_policy(&self) -> Stdio { + if self.forward_standard_streams { + Stdio::piped() + } else { + Stdio::null() + } + } + /// Returns all arguments that the subprocess would be spawned with. pub fn get_arguments(&self) -> Vec<OsString> { let mut args = vec![]; |
