summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-01-13 15:21:27 +0100
committerErik Larkö <erik@mullvad.net>2017-01-13 15:21:27 +0100
commit4d91395f6fdad1792bf0b1610f2c978bc9d1d987 (patch)
tree7b76a029543e295bb1f8d975fd546ba62bae9097 /src
parent7cf592b33fe4cb377694e9f9ec3230b73273013c (diff)
parent1b7ca8272a9f8d914da13e2ea3e852588f1e23e7 (diff)
downloadmullvadvpn-4d91395f6fdad1792bf0b1610f2c978bc9d1d987.tar.xz
mullvadvpn-4d91395f6fdad1792bf0b1610f2c978bc9d1d987.zip
Merge remote-tracking branch 'origin/std-streams'
Diffstat (limited to 'src')
-rw-r--r--src/process/mod.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/process/mod.rs b/src/process/mod.rs
index 0538eb8c62..52d4229d17 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>,
+ pipe_output: bool,
}
impl OpenVpnCommand {
@@ -29,6 +30,7 @@ impl OpenVpnCommand {
openvpn_bin: OsString::from(openvpn_bin.as_ref()),
config: None,
remotes: vec![],
+ pipe_output: true,
}
}
@@ -45,6 +47,14 @@ impl OpenVpnCommand {
Ok(self)
}
+ /// If piping the standard streams, stdout and stderr will be available to the parent process.
+ /// This is the default behavior. If you want the equivalence of attaching the child streams to
+ /// /dev/null, invoke this method with false.
+ pub fn pipe_output(&mut self, pipe_output: bool) -> &mut Self {
+ self.pipe_output = pipe_output;
+ 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 +66,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_output_pipe_policy())
+ .stderr(self.get_output_pipe_policy());
command
}
+ fn get_output_pipe_policy(&self) -> Stdio {
+ if self.pipe_output {
+ 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![];