diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-06-21 03:26:35 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-06-21 03:26:35 +0200 |
| commit | 14e3220ec993e2be9c6f37a65710b887bae5f49e (patch) | |
| tree | 8fca5d8939419d0f01a890d0fbf51a4d292bcf3a | |
| parent | e1ff9a3c72d06f20c4e47517cf0f65f11ceb7d66 (diff) | |
| parent | 6a30a8fb16e37e7f699af36a228cb079fe01a224 (diff) | |
| download | mullvadvpn-14e3220ec993e2be9c6f37a65710b887bae5f49e.tar.xz mullvadvpn-14e3220ec993e2be9c6f37a65710b887bae5f49e.zip | |
Merge branch 'smarter-plugin-finding'
| -rw-r--r-- | talpid_core/src/tunnel/mod.rs | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/talpid_core/src/tunnel/mod.rs b/talpid_core/src/tunnel/mod.rs index aead09b13b..6060e13208 100644 --- a/talpid_core/src/tunnel/mod.rs +++ b/talpid_core/src/tunnel/mod.rs @@ -2,6 +2,7 @@ use net; use openvpn_ffi::OpenVpnPluginEvent; use process::openvpn::OpenVpnCommand; use std::io; +use std::path::{Path, PathBuf}; /// A module for all OpenVPN related tunnel management. pub mod openvpn; @@ -15,6 +16,10 @@ mod errors { TunnelMonitoringError { description("Error while setting up or processing events from the VPN tunnel") } + /// The OpenVPN plugin was not found. + PluginNotFound { + description("No OpenVPN plugin found") + } } } } @@ -59,7 +64,7 @@ impl TunnelMonitor { None => debug!("Ignoring OpenVpnEvent {:?}", event), }; let cmd = Self::create_openvpn_cmd(remote); - let monitor = openvpn::OpenVpnMonitor::new(cmd, on_openvpn_event, get_plugin_path()) + let monitor = openvpn::OpenVpnMonitor::new(cmd, on_openvpn_event, get_plugin_path()?) .chain_err(|| ErrorKind::TunnelMonitoringError)?; Ok(TunnelMonitor { monitor }) } @@ -97,16 +102,26 @@ impl CloseHandle { // TODO(linus): Temporary implementation for getting plugin path during development. -fn get_plugin_path() -> &'static str { - if cfg!(all(unix, not(target_os = "macos"))) { - "./target/debug/libtalpid_openvpn_plugin.so" - } else if cfg!(target_os = "macos") { - "./target/debug/libtalpid_openvpn_plugin.dylib" +fn get_plugin_path() -> Result<PathBuf> { + let dirs = &["./target/debug", "."]; + let filename = if cfg!(target_os = "macos") { + "libtalpid_openvpn_plugin.dylib" + } else if cfg!(unix) { + "libtalpid_openvpn_plugin.so" } else if cfg!(windows) { - "./target/debug/libtalpid_openvpn_plugin.dll" + "libtalpid_openvpn_plugin.dll" } else { - panic!("Unsupported platform"); + bail!(ErrorKind::PluginNotFound); + }; + + for dir in dirs { + let path = Path::new(dir).join(filename); + if path.exists() { + debug!("Using OpenVPN plugin at {}", path.to_string_lossy()); + return Ok(path); + } } + Err(ErrorKind::PluginNotFound.into()) } // TODO(linus): Temporary implementation for getting hold of a config location. |
