diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-09-26 08:50:41 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-09-26 08:50:41 +0200 |
| commit | 30ce3cccbba086f7a0c668e7950cb539a0eefccc (patch) | |
| tree | 785203be81c3eeea98bcea2f85f8daf6be440fe1 /talpid-core/src | |
| parent | 9b5c05408b3589751239cf8363a2c190c7f4371e (diff) | |
| parent | 66b0e0bc224b6178e39971d58cc332bff750283a (diff) | |
| download | mullvadvpn-30ce3cccbba086f7a0c668e7950cb539a0eefccc.tar.xz mullvadvpn-30ce3cccbba086f7a0c668e7950cb539a0eefccc.zip | |
Merge branch 'log-openvpn-output'2017.1-beta1
Diffstat (limited to 'talpid-core/src')
| -rw-r--r-- | talpid-core/src/process/openvpn.rs | 13 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/mod.rs | 18 |
2 files changed, 28 insertions, 3 deletions
diff --git a/talpid-core/src/process/openvpn.rs b/talpid-core/src/process/openvpn.rs index 3398a9baa9..ac3e5911b1 100644 --- a/talpid-core/src/process/openvpn.rs +++ b/talpid-core/src/process/openvpn.rs @@ -37,6 +37,7 @@ pub struct OpenVpnCommand { user_pass_path: Option<PathBuf>, ca: Option<PathBuf>, plugin: Option<(PathBuf, Vec<String>)>, + log: Option<PathBuf>, } impl OpenVpnCommand { @@ -50,6 +51,7 @@ impl OpenVpnCommand { user_pass_path: None, ca: None, plugin: None, + log: None, } } @@ -84,6 +86,12 @@ impl OpenVpnCommand { self } + /// Sets a log file path. + pub fn log<P: AsRef<Path>>(&mut self, path: P) -> &mut Self { + self.log = Some(path.as_ref().to_path_buf()); + self + } + /// Build a runnable expression from the current state of the command. pub fn build(&self) -> duct::Expression { debug!("Building expression: {}", &self); @@ -113,6 +121,11 @@ impl OpenVpnCommand { args.extend(plugin_args.iter().map(OsString::from)); } + if let Some(ref path) = self.log { + args.push(OsString::from("--log")); + args.push(OsString::from(path)) + } + args.extend(Self::security_arguments().iter().map(OsString::from)); args diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs index b9e8aa8fa2..6ff4c7d2b9 100644 --- a/talpid-core/src/tunnel/mod.rs +++ b/talpid-core/src/tunnel/mod.rs @@ -107,13 +107,18 @@ pub struct TunnelMonitor { impl TunnelMonitor { /// Creates a new `TunnelMonitor` that connects to the given remote and notifies `on_event` /// on tunnel state changes. - pub fn new<L>(remote: net::Endpoint, account_token: &str, on_event: L) -> Result<Self> + pub fn new<L>( + remote: net::Endpoint, + account_token: &str, + log: Option<&Path>, + on_event: L, + ) -> Result<Self> where L: Fn(TunnelEvent) + Send + Sync + 'static, { let user_pass_file = Self::create_user_pass_file(account_token) .chain_err(|| ErrorKind::CredentialsWriteError)?; - let cmd = Self::create_openvpn_cmd(remote, user_pass_file.as_ref()); + let cmd = Self::create_openvpn_cmd(remote, user_pass_file.as_ref(), log); let user_pass_file_path = user_pass_file.to_path_buf(); let on_openvpn_event = move |event, env| { @@ -135,7 +140,11 @@ impl TunnelMonitor { }) } - fn create_openvpn_cmd(remote: net::Endpoint, user_pass_file: &Path) -> OpenVpnCommand { + fn create_openvpn_cmd( + remote: net::Endpoint, + user_pass_file: &Path, + log: Option<&Path>, + ) -> OpenVpnCommand { let mut cmd = OpenVpnCommand::new(Self::get_openvpn_bin()); if let Some(config) = Self::get_config_path() { cmd.config(config); @@ -143,6 +152,9 @@ impl TunnelMonitor { cmd.remote(remote) .user_pass(user_pass_file) .ca(Self::get_ca_path()); + if let Some(log) = log { + cmd.log(log); + } cmd } |
