diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2018-05-15 15:37:09 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2018-05-22 12:49:57 +0200 |
| commit | 01afa29fac8b44be0ddf0ef666fc4771069bb32b (patch) | |
| tree | 84a2f97b932d3c7ff408b780dd34637126a166fa | |
| parent | c41274e006f4184055251eea9c8e0c3a606b7615 (diff) | |
| download | mullvadvpn-01afa29fac8b44be0ddf0ef666fc4771069bb32b.tar.xz mullvadvpn-01afa29fac8b44be0ddf0ef666fc4771069bb32b.zip | |
Try stopping openvpn by closing it's stdin
| -rw-r--r-- | talpid-core/src/process/openvpn.rs | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/talpid-core/src/process/openvpn.rs b/talpid-core/src/process/openvpn.rs index 41b6f25244..4884b593c9 100644 --- a/talpid-core/src/process/openvpn.rs +++ b/talpid-core/src/process/openvpn.rs @@ -1,5 +1,6 @@ use duct; extern crate os_pipe; +extern crate libc; use std::ffi::{OsStr, OsString}; use std::fmt; @@ -223,7 +224,7 @@ pub struct OpenVpnProcHandle { /// Duct handle pub inner: duct::Handle, /// Standard input handle - pub stdin: Arc<Mutex<PipeWriter>>, + pub stdin: PipeWriter, } /// Impl for proc handle @@ -244,19 +245,41 @@ impl OpenVpnProcHandle { Ok(Self { inner: proc_handle, - stdin: Arc::new(Mutex::new(writer)), + stdin: writer, }) } } impl StoppableProcess for OpenVpnProcHandle { - /// Writes a byte to the standard input of the OpenVPN process - Mullvad's OpenVPN is modified - /// to exit when it reads a particular byte from STDIN. + #[cfg(unix)] + /// Closes STDIN to stop the openvpn process fn stop(&self) -> io::Result<()> { - use std::io::Write; - let mut writer = self.stdin.lock().unwrap(); - writer.write_all(&[Self::KILL_BYTE]) + use std::io::Error; + use std::os::unix::io::AsRawFd; + let raw_fd = self.stdin.as_raw_fd(); + unsafe { + let err = libc::close(raw_fd); + match err { + 0 => Ok(()), + err => Err(Error::from_raw_os_error(err)), + } + } + } + + #[cfg(windows)] + fn stop(&self) -> io::Result<()> { + use std::io::Error; + use std::os::unix::io::AsRawHandle; + use libc::funcs::extra::kernel32; + let raw_handle = self.stdin.as_raw_handle(); + unsafe { + let success = CloseHandle(raw_handle); + match err { + 0 => Err(Error::last_os_error()), + _ => Ok(()), + } + } } fn kill(&self) -> io::Result<()> { |
