diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-08-28 18:18:12 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-08-28 18:18:12 +0200 |
| commit | d8c1fc6e5584ce98360fe9c979f543afa8d17346 (patch) | |
| tree | 2af68b2ec131fde1096bada2cc84fddae4cba301 | |
| parent | f4aec4863a206b7585b7de4885cc8f6fb758b051 (diff) | |
| parent | 3d1de505504022b571891e71275042c096cd7148 (diff) | |
| download | mullvadvpn-d8c1fc6e5584ce98360fe9c979f543afa8d17346.tar.xz mullvadvpn-d8c1fc6e5584ce98360fe9c979f543afa8d17346.zip | |
Merge branch 'add-tests'
| -rw-r--r-- | Cargo.lock | 359 | ||||
| -rw-r--r-- | talpid-core/src/process/unix.rs | 51 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/openvpn.rs | 188 |
3 files changed, 542 insertions, 56 deletions
diff --git a/Cargo.lock b/Cargo.lock index 750463b577..b7e931c7bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,6 +10,15 @@ dependencies = [ ] [[package]] +name = "advapi32-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "aho-corasick" version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -80,6 +89,15 @@ dependencies = [ ] [[package]] +name = "base64" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "bindgen" version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -179,6 +197,32 @@ dependencies = [ ] [[package]] +name = "core-foundation" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "core-foundation-sys" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crypt32-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "ctrlc" version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -273,11 +317,25 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "foreign-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "futures" version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "futures-cpupool" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "gcc" version = "0.3.51" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -305,6 +363,42 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "hyper" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-cpupool 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "mime 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-core 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-proto 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicase 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hyper-tls" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", + "native-tls 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-core 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-tls 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "idna" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -339,6 +433,33 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "jsonrpc-client-core" +version = "0.1.0" +source = "git+https://github.com/mullvad/jsonrpc-client-rs?branch=rewrite-to-async#7ed796714c6b910053b8fe303d591582bfa917cb" +dependencies = [ + "error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 7.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "jsonrpc-client-http" +version = "0.1.0" +source = "git+https://github.com/mullvad/jsonrpc-client-rs?branch=rewrite-to-async#7ed796714c6b910053b8fe303d591582bfa917cb" +dependencies = [ + "error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-client-core 0.1.0 (git+https://github.com/mullvad/jsonrpc-client-rs?branch=rewrite-to-async)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-core 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "jsonrpc-core" version = "7.0.1" source = "git+https://github.com/paritytech/jsonrpc#91cb1a97c836d710ece2f1e3ae7fbab321cfc6f7" @@ -351,6 +472,18 @@ dependencies = [ ] [[package]] +name = "jsonrpc-core" +version = "7.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "jsonrpc-macros" version = "7.0.1" source = "git+https://github.com/paritytech/jsonrpc#91cb1a97c836d710ece2f1e3ae7fbab321cfc6f7" @@ -406,6 +539,11 @@ dependencies = [ ] [[package]] +name = "language-tags" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "lazy_static" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -459,6 +597,14 @@ dependencies = [ ] [[package]] +name = "mime" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicase 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "mio" version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -518,6 +664,9 @@ dependencies = [ "ctrlc 3.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "fern 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-client-core 0.1.0 (git+https://github.com/mullvad/jsonrpc-client-rs?branch=rewrite-to-async)", + "jsonrpc-client-http 0.1.0 (git+https://github.com/mullvad/jsonrpc-client-rs?branch=rewrite-to-async)", "jsonrpc-core 7.0.1 (git+https://github.com/paritytech/jsonrpc)", "jsonrpc-macros 7.0.1 (git+https://github.com/paritytech/jsonrpc)", "jsonrpc-pubsub 7.0.1 (git+https://github.com/paritytech/jsonrpc)", @@ -544,6 +693,18 @@ dependencies = [ ] [[package]] +name = "native-tls" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "openssl 0.9.17 (registry+https://github.com/rust-lang/crates.io-index)", + "schannel 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "net2" version = "0.2.29" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -607,6 +768,14 @@ version = "0.1.39" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "num_cpus" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "ole32-sys" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -616,6 +785,29 @@ dependencies = [ ] [[package]] +name = "openssl" +version = "0.9.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "foreign-types 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.17 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "openssl-sys" +version = "0.9.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "openvpn-plugin" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -690,6 +882,11 @@ dependencies = [ ] [[package]] +name = "pkg-config" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "quasi" version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -755,11 +952,72 @@ version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "rustc_version" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "safemem" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "schannel" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "advapi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crypt32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "secur32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "scoped-tls" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "secur32-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "security-framework" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "core-foundation 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "security-framework-sys" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "serde" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -834,6 +1092,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "smallvec" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "smallvec" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -908,6 +1171,11 @@ dependencies = [ ] [[package]] +name = "take" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "talpid-core" version = "0.1.0" dependencies = [ @@ -943,6 +1211,14 @@ dependencies = [ ] [[package]] +name = "tempdir" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "term" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1026,6 +1302,42 @@ dependencies = [ ] [[package]] +name = "tokio-proto" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "take 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-core 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-service" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-tls" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "native-tls 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-core 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "toml" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1034,6 +1346,14 @@ dependencies = [ ] [[package]] +name = "unicase" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "unicode-bidi" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1102,6 +1422,11 @@ dependencies = [ ] [[package]] +name = "vcpkg" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "vec_map" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1152,6 +1477,7 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] +"checksum advapi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e06588080cb19d0acb6739808aafa5f26bfb2ca015b2b6370028b44cf7cb8a9a" "checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699" "checksum ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23ac7c30002a5accbf7e8987d0632fa6de155b7c3d39d0067317a391e00a2ef6" "checksum app_dirs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b7d1c0d48a81bbb13043847f957971f4d87c81542d80ece5e84ba3cba4058fd4" @@ -1160,6 +1486,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d912da0db7fa85514874458ca3651fe2cddace8d0b0505571dbdcd41ab490159" "checksum backtrace 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "72f9b4182546f4b04ebc4ab7f84948953a118bd6021a1b6a6c909e3e94f6be76" "checksum backtrace-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3a0d842ea781ce92be2bf78a9b38883948542749640b8378b3b2f03d1fd9f1ff" +"checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" "checksum bindgen 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0c338079dafc81bef7d581f494b906603d12359c4306979eae6ca081925a4984" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4" @@ -1171,6 +1498,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9" "checksum clang-sys 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "611ec2e3a7623afd8a8c0d027887b6b55759d894abbf5fe11b9dc11b50d5b49a" "checksum clap 2.25.0 (registry+https://github.com/rust-lang/crates.io-index)" = "867a885995b4184be051b70a592d4d70e32d7a188db6e8dff626af286a962771" +"checksum core-foundation 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25bfd746d203017f7d5cbd31ee5d8e17f94b6521c7af77ece6c9e4b2d4b16c67" +"checksum core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "065a5d7ffdcbc8fa145d6f0746f3555025b9097a9e9cda59f7467abae670c78d" +"checksum crypt32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e34988f7e069e0b2f3bfc064295161e489b2d4e04a2e4248fb94360cdf00b4ec" "checksum ctrlc 3.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c663ee353d7e03e4f895af66ff7d3537f94c09deaa341a2f450684a3d45cb46" "checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" "checksum derive_builder 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "03600ae366b6eb2314e54d62adc833d9866da03798acc61c61789654ceaa227a" @@ -1182,22 +1512,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8" "checksum fern 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "89273e0d0e210f69600048a209a00e163560b51e3ef51c3942304e9b8aa8b47a" "checksum fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc484842f1e2884faf56f529f960cc12ad8c71ce96cc7abba0a067c98fee344" +"checksum foreign-types 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e4056b9bd47f8ac5ba12be771f77a0dae796d1bbaaf5fd0b9c2d38b69b8a29d" "checksum futures 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4b63a4792d4f8f686defe3b39b92127fea6344de5d38202b2ee5a11bbbf29d6a" +"checksum futures-cpupool 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a283c84501e92cade5ea673a2a7ca44f71f209ccdd302a3e0896f50083d2c5ff" "checksum gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)" = "120d07f202dcc3f72859422563522b66fe6463a4c513df062874daad05f85f0a" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum globset 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90d069fe6beb9be359ef505650b3f73228c5591a3c4b1f32be2f4f44459ffa3a" "checksum httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "af2f2dd97457e8fb1ae7c5a420db346af389926e36f43768b96f101546b04a07" +"checksum hyper 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "641abc3e3fcf0de41165595f801376e01106bca1fd876dda937730e477ca004c" +"checksum hyper-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c81fa95203e2a6087242c38691a0210f23e9f3f8f944350bd676522132e2985" "checksum idna 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2233d4940b1f19f0418c158509cd7396b8d70a5db5705ce410914dc8fa603b37" "checksum ioctl-sys 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5e2c4b26352496eaaa8ca7cfa9bd99e93419d3f7983dc6e99c2a35fe9e33504a" "checksum iovec 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "29d062ee61fccdf25be172e70f34c9f6efc597e1fb8f6526e8437b2046ab26be" "checksum ipnetwork 0.12.6 (registry+https://github.com/rust-lang/crates.io-index)" = "232e76922883005380e831068f731ef0305541c9f77b30df3a1635047b16f370" "checksum itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eb2f404fbc66fd9aac13e998248505e7ecb2ad8e44ab6388684c5fb11c6c251c" +"checksum jsonrpc-client-core 0.1.0 (git+https://github.com/mullvad/jsonrpc-client-rs?branch=rewrite-to-async)" = "<none>" +"checksum jsonrpc-client-http 0.1.0 (git+https://github.com/mullvad/jsonrpc-client-rs?branch=rewrite-to-async)" = "<none>" "checksum jsonrpc-core 7.0.1 (git+https://github.com/paritytech/jsonrpc)" = "<none>" +"checksum jsonrpc-core 7.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "903e5eee845f3d83c1436d12848d97b1247cf850ff06a8e1db2f1ce3543af2cf" "checksum jsonrpc-macros 7.0.1 (git+https://github.com/paritytech/jsonrpc)" = "<none>" "checksum jsonrpc-pubsub 7.0.1 (git+https://github.com/paritytech/jsonrpc)" = "<none>" "checksum jsonrpc-server-utils 7.0.1 (git+https://github.com/paritytech/jsonrpc)" = "<none>" "checksum jsonrpc-ws-server 7.0.1 (git+https://github.com/paritytech/jsonrpc)" = "<none>" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +"checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "cf186d1a8aa5f5bee5fd662bc9c1b949e0259e1bcc379d1f006847b0080c7417" "checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" "checksum lazycell 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce12306c4739d86ee97c23139f3a34ddf0387bbf181bc7929d287025a8c3ef6b" @@ -1207,9 +1545,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" +"checksum mime 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "153f98dde2b135dece079e5478ee400ae1bab13afa52d66590eacfc40e912435" "checksum mio 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9e965267d4d58496fc4f740e9861118367f13570cadf66316ed2c3f2f14d87c7" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum mktemp 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "77001ceb9eed65439f3dc2a2543f9ba1417d912686bf224a7738d0966e6dcd69" +"checksum native-tls 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04b781c9134a954c84f0594b9ab3f5606abc516030388e8511887ef4c204a1e5" "checksum net2 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "bc01404e7568680f1259aa5729539f221cb1e6d047a0d9053cab4be8a73b5d67" "checksum nix 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "47e49f6982987135c5e9620ab317623e723bd06738fd85377e8d55f57c8b6487" "checksum nom 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "06989cbd367e06f787a451f3bc67d8c3e0eaa10b461cc01152ffab24261a31b1" @@ -1217,7 +1557,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "ef1a4bf6f9174aa5783a9b4cc892cacd11aebad6c69ad027a0b65c6ca5f8aa37" "checksum num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d1891bd7b936f12349b7d1403761c8a0b85a18b148e9da4429d5d102c1a41e" "checksum num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "1708c0628602a98b52fad936cf3edb9a107af06e52e49fdf0707e884456a6af6" +"checksum num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584" "checksum ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2c49021782e5233cd243168edfa8037574afed4eba4bbaf538b3d8d1789d8c" +"checksum openssl 0.9.17 (registry+https://github.com/rust-lang/crates.io-index)" = "085aaedcc89a2fac1eb2bc19cd66f29d4ea99fec60f82a5f3a88a6be7dbd90b5" +"checksum openssl-sys 0.9.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7e3a9845a4c9fdb321931868aae5549e96bb7b979bf9af7de03603d74691b5f3" "checksum openvpn-plugin 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "99c05a2229a24799412627dd22730729796aca97405dedc297a622536f37fb3b" "checksum os_pipe 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "998bfbb3042e715190fe2a41abfa047d7e8cb81374d2977d7f100eacd8619cb1" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" @@ -1226,6 +1569,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" "checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356" "checksum pfctl 0.1.0 (git+https://github.com/mullvad/pfctl-rs.git)" = "<none>" +"checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" "checksum quasi 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18c45c4854d6d1cf5d531db97c75880feb91c958b0720f4ec1057135fec358b3" "checksum quasi_codegen 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "51b9e25fa23c044c1803f43ca59c98dac608976dd04ce799411edd58ece776d4" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" @@ -1235,7 +1579,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db" "checksum rustc-demangle 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3058a43ada2c2d0b92b3ae38007a2d0fa5e9db971be260e0171408a4ff471c95" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" +"checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" +"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" +"checksum schannel 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "14a5f8491ae5fc8c51aded1f5806282a0218b4d69b1b76913a0559507e559b90" "checksum scoped-tls 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f417c22df063e9450888a7561788e9bd46d3bb3c1466435b4eccb903807f147d" +"checksum secur32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f412dfa83308d893101dd59c10d6fda8283465976c28c287c5c855bf8d216bc" +"checksum security-framework 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "dfa44ee9c54ce5eecc9de7d5acbad112ee58755239381f687e564004ba4a2332" +"checksum security-framework-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "5421621e836278a0b139268f36eee0dc7e389b784dc3f79d8f11aabadf41bead" +"checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" "checksum serde 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6a7c6b751a2e8d5df57a5ff71b5b4fc8aaee9ee28ff1341d640dd130bb5f4f7a" "checksum serde_derive 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "2f6ca58905ebd3c3b285a8a6d4f3ac92b92c0d7951d5649b1bdd212549c06639" "checksum serde_derive_internals 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "37aee4e0da52d801acfbc0cc219eb1eda7142112339726e427926a6f6ee65d3a" @@ -1245,6 +1596,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum shell32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72f20b8f3c060374edb8046591ba28f62448c369ccbdc7b02075103fb3a9e38d" "checksum simple-signal 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c1eb01a0c2d12db9e52684e73038eac812494e5937571ae2631f5cf53dc56687" "checksum slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4fcaed89ab08ef143da37bc52adbcc04d4a69014f4c1208d6b51f0c47bc23" +"checksum smallvec 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4c8cbcd6df1e117c2210e13ab5109635ad68a929fcbb8964dc965b76cb5ee013" "checksum smallvec 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "26aa2afb825226fa29f0315de04d5a4af5fd44adadf837296accc01a49929724" "checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" @@ -1254,6 +1606,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum syntex_errors 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "867cc5c2d7140ae7eaad2ae9e8bf39cb18a67ca651b7834f88d46ca98faadb9c" "checksum syntex_pos 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "13ad4762fe52abc9f4008e85c4fb1b1fe3aa91ccb99ff4826a439c7c598e1047" "checksum syntex_syntax 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6e0e4dbae163dd98989464c23dd503161b338790640e11537686f2ef0f25c791" +"checksum take 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b157868d8ac1f56b64604539990685fa7611d8fa9e5476cf0c02cf34d32917c5" +"checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6" "checksum term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fa63644f74ce96fbeb9b794f66aff2a52d601cbd5e80f4b97123e3899f4570f1" "checksum term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2b6b55df3198cc93372e85dd2ed817f0e38ce8cc0f22eb32391bfad9c4bf209" "checksum textwrap 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f86300c3e7416ee233abd7cda890c492007a3980f941f79185c753a701257167" @@ -1262,7 +1616,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" "checksum tokio-core 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6a20ba4738d283cac7495ca36e045c80c2a8df3e05dd0909b17a06646af5a7ed" "checksum tokio-io 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c2c3ce9739f7387a0fa65b5421e81feae92e04d603f008898f4257790ce8c2db" +"checksum tokio-proto 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8fbb47ae81353c63c487030659494b295f6cb6576242f907f203473b191b0389" +"checksum tokio-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24da22d077e0f15f55162bdbdc661228c1581892f52074fb242678d015b45162" +"checksum tokio-tls 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d88e411cac1c87e405e4090be004493c5d8072a370661033b1a64ea205ec2e13" "checksum toml 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b0601da6c97135c8d330c7a13a013ca6cd4143221b01de2f8d4edc50a9e551c7" +"checksum unicase 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e01da42520092d0cd2d6ac3ae69eb21a22ad43ff195676b86f8c37f487d6b80" "checksum unicode-bidi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a6a2c4e3710edd365cd7e78383153ed739fa31af19f9172f72d3575060f5a43a" "checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f" "checksum unicode-segmentation 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18127285758f0e2c6cf325bb3f3d138a12fee27de4f23e146cd6a179f26c2cf3" @@ -1273,6 +1631,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" "checksum uuid 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "78c590b5bd79ed10aad8fb75f078a59d8db445af6c743e55c4a53227fc01c13f" "checksum uuid 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcc7e3b898aa6f6c08e5295b6c89258d1331e9ac578cc992fb818759951bdc22" +"checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b" "checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" diff --git a/talpid-core/src/process/unix.rs b/talpid-core/src/process/unix.rs index 64599a6930..189945257d 100644 --- a/talpid-core/src/process/unix.rs +++ b/talpid-core/src/process/unix.rs @@ -4,30 +4,43 @@ use duct; use duct::unix::HandleExt; use std::io; -use std::sync::{Arc, mpsc}; use std::thread; -use std::time::Duration; +use std::time::{Duration, Instant}; -/// Kills a process by first sending it the `SIGTERM` signal and then wait up to `timeout`. If the -/// process has not died after the timeout has expired it is killed. -pub fn nice_kill(handle: Arc<duct::Handle>, timeout: Duration) -> io::Result<()> { - trace!("Sending SIGTERM to child process"); - handle.send_signal(libc::SIGTERM)?; +static POLL_INTERVAL_MS: u64 = 50; - if wait_timeout(handle.clone(), timeout) { - debug!("Child process exited from SIGTERM"); - Ok(()) - } else { - debug!("Child process did not exit from SIGTERM, sending SIGKILL"); - handle.kill() +/// Extra methods for terminating `duct::Handle` instances. +pub trait HandleKillExt { + /// Kills a process by first sending it the `SIGTERM` signal and then wait up to `timeout`. + /// If the process has not died after the timeout has expired it is killed. + fn nice_kill(&self, timeout: Duration) -> io::Result<()>; +} + +impl HandleKillExt for duct::Handle { + fn nice_kill(&self, timeout: Duration) -> io::Result<()> { + trace!("Sending SIGTERM to child process"); + self.send_signal(libc::SIGTERM)?; + + if wait_timeout(self, timeout)? { + debug!("Child process exited from SIGTERM"); + Ok(()) + } else { + debug!("Child process did not exit from SIGTERM, sending SIGKILL"); + self.kill() + } } } /// Wait for a process to die for a maximum of `timeout`. Returns true if the process died within -/// the timeout. Warning, if the process does not exit in the given time, this function will leave -/// a thread running until it does exit. -fn wait_timeout(handle: Arc<duct::Handle>, timeout: Duration) -> bool { - let (stop, stopped) = mpsc::channel(); - thread::spawn(move || { let _ = stop.send(handle.wait().is_ok()); }); - stopped.recv_timeout(timeout).unwrap_or(false) +/// the timeout. +fn wait_timeout(handle: &duct::Handle, timeout: Duration) -> io::Result<bool> { + let timer = Instant::now(); + while timer.elapsed() < timeout { + match handle.try_wait() { + Ok(None) => thread::sleep(Duration::from_millis(POLL_INTERVAL_MS)), + Ok(Some(_)) => return Ok(true), + Err(e) => return Err(e), + } + } + Ok(false) } diff --git a/talpid-core/src/tunnel/openvpn.rs b/talpid-core/src/tunnel/openvpn.rs index f545a1d4d1..81d4bd88a4 100644 --- a/talpid-core/src/tunnel/openvpn.rs +++ b/talpid-core/src/tunnel/openvpn.rs @@ -6,6 +6,7 @@ use process::openvpn::OpenVpnCommand; use std::collections::HashMap; use std::io; use std::path::Path; +use std::process::ExitStatus; use std::result::Result as StdResult; use std::sync::{Arc, mpsc}; use std::sync::atomic::{AtomicBool, Ordering}; @@ -38,16 +39,25 @@ lazy_static!{ /// Struct for monitoring an OpenVPN process. -pub struct OpenVpnMonitor { - child: Arc<duct::Handle>, +pub struct OpenVpnMonitor<C: OpenVpnBuilder = OpenVpnCommand> { + child: Arc<C::ProcessHandle>, event_dispatcher: Option<OpenVpnEventDispatcher>, closed: Arc<AtomicBool>, } -impl OpenVpnMonitor { +impl OpenVpnMonitor<OpenVpnCommand> { /// Creates a new `OpenVpnMonitor` with the given listener and using the plugin at the given /// path. - pub fn new<L, P>(mut cmd: OpenVpnCommand, on_event: L, plugin_path: P) -> Result<Self> + pub fn new<L, P>(cmd: OpenVpnCommand, on_event: L, plugin_path: P) -> Result<Self> + where L: Fn(OpenVpnPluginEvent, HashMap<String, String>) + Send + Sync + 'static, + P: AsRef<Path> + { + Self::new_internal(cmd, on_event, plugin_path) + } +} + +impl<C: OpenVpnBuilder> OpenVpnMonitor<C> { + fn new_internal<L, P>(mut cmd: C, on_event: L, plugin_path: P) -> Result<OpenVpnMonitor<C>> where L: Fn(OpenVpnPluginEvent, HashMap<String, String>) + Send + Sync + 'static, P: AsRef<Path> { @@ -55,9 +65,7 @@ impl OpenVpnMonitor { .chain_err(|| ErrorKind::EventDispatcherError)?; cmd.plugin(plugin_path, vec![event_dispatcher.address().to_owned()]); - let child = cmd.build() - .start() - .chain_err(|| ErrorKind::ChildProcessError("Failed to start"))?; + let child = cmd.start().chain_err(|| ErrorKind::ChildProcessError("Failed to start"))?; Ok( OpenVpnMonitor { @@ -70,7 +78,7 @@ impl OpenVpnMonitor { /// Creates a handle to this monitor, allowing the tunnel to be closed while some other thread /// is blocked in `wait`. - pub fn close_handle(&self) -> OpenVpnCloseHandle { + pub fn close_handle(&self) -> OpenVpnCloseHandle<C::ProcessHandle> { OpenVpnCloseHandle { child: self.child.clone(), closed: self.closed.clone(), @@ -81,8 +89,8 @@ impl OpenVpnMonitor { /// for the process or in the event dispatcher. pub fn wait(mut self) -> Result<()> { match self.wait_result() { - WaitResult::Child(Ok(exit_status)) => { - if exit_status.success() || self.closed.load(Ordering::SeqCst) { + WaitResult::Child(Ok(exit_status), closed) => { + if exit_status.success() || closed { debug!( "OpenVPN exited, as expected, with exit status: {}", exit_status @@ -93,7 +101,7 @@ impl OpenVpnMonitor { Err(ErrorKind::ChildProcessError("Died unexpectedly").into()) } } - WaitResult::Child(Err(e)) => { + WaitResult::Child(Err(e), _) => { error!("OpenVPN process wait error: {}", e); Err(e).chain_err(|| ErrorKind::ChildProcessError("Error when waiting")) } @@ -111,6 +119,7 @@ impl OpenVpnMonitor { /// returned this returns the earliest result. fn wait_result(&mut self) -> WaitResult { let child_wait_handle = self.child.clone(); + let closed_handle = self.closed.clone(); let child_close_handle = self.close_handle(); let event_dispatcher = self.event_dispatcher.take().unwrap(); let dispatcher_handle = event_dispatcher.close_handle(); @@ -120,8 +129,9 @@ impl OpenVpnMonitor { thread::spawn( move || { - let result = child_wait_handle.wait().map(|output| output.status); - child_tx.send(WaitResult::Child(result)).unwrap(); + let result = child_wait_handle.wait(); + let closed = closed_handle.load(Ordering::SeqCst); + child_tx.send(WaitResult::Child(result, closed)).unwrap(); dispatcher_handle.close(); }, ); @@ -140,36 +150,76 @@ impl OpenVpnMonitor { } /// A handle to an `OpenVpnMonitor` for closing it. -pub struct OpenVpnCloseHandle { - child: Arc<duct::Handle>, +pub struct OpenVpnCloseHandle<H: ProcessHandle = duct::Handle> { + child: Arc<H>, closed: Arc<AtomicBool>, } -impl OpenVpnCloseHandle { +impl<H: ProcessHandle> OpenVpnCloseHandle<H> { /// Kills the underlying OpenVPN process, making the `OpenVpnMonitor::wait` method return. pub fn close(self) -> io::Result<()> { if !self.closed.swap(true, Ordering::SeqCst) { - self.kill_openvpn() + self.child.kill() } else { Ok(()) } } +} - #[cfg(unix)] - fn kill_openvpn(self) -> io::Result<()> { - ::process::unix::nice_kill(self.child, *OPENVPN_DIE_TIMEOUT) +/// Internal enum to differentiate between if the child process or the event dispatcher died first. +enum WaitResult { + Child(io::Result<ExitStatus>, bool), + EventDispatcher(talpid_ipc::Result<()>), +} + +/// Trait for types acting as OpenVPN process starters for `OpenVpnMonitor`. +pub trait OpenVpnBuilder { + /// The type of handles to subprocesses this builder produces. + type ProcessHandle: ProcessHandle; + + /// Set the OpenVPN plugin to the given values. + fn plugin<P: AsRef<Path>>(&mut self, path: P, args: Vec<String>) -> &mut Self; + + /// Spawn the subprocess and return a handle. + fn start(&self) -> io::Result<Self::ProcessHandle>; +} + +/// Trait for types acting as handles to subprocesses for `OpenVpnMonitor` +pub trait ProcessHandle: Send + Sync + 'static { + /// Block until the subprocess exits or there is an error in the wait syscall. + fn wait(&self) -> io::Result<ExitStatus>; + + /// Kill the subprocess. + fn kill(&self) -> io::Result<()>; +} + +impl OpenVpnBuilder for OpenVpnCommand { + type ProcessHandle = duct::Handle; + + fn plugin<P: AsRef<Path>>(&mut self, path: P, args: Vec<String>) -> &mut Self { + self.plugin(path, args) } - #[cfg(not(unix))] - fn kill_openvpn(self) -> io::Result<()> { - self.child.kill() + fn start(&self) -> io::Result<duct::Handle> { + self.build().start() } } -/// Internal enum to differentiate between if the child process or the event dispatcher died first. -enum WaitResult { - Child(io::Result<::std::process::ExitStatus>), - EventDispatcher(talpid_ipc::Result<()>), +impl ProcessHandle for duct::Handle { + fn wait(&self) -> io::Result<ExitStatus> { + self.wait().map(|output| output.status) + } + + #[cfg(unix)] + fn kill(&self) -> io::Result<()> { + use process::unix::HandleKillExt; + self.nice_kill(*OPENVPN_DIE_TIMEOUT) + } + + #[cfg(not(unix))] + fn kill(&self) -> io::Result<()> { + duct::Handle::kill(self) + } } @@ -246,17 +296,81 @@ impl<L> OpenVpnEventApi for OpenVpnEventApiImpl<L> #[cfg(test)] mod tests { use super::*; + use std::path::{Path, PathBuf}; + + use std::sync::{Arc, Mutex}; + + #[derive(Default, Clone)] + struct TestOpenVpnBuilder { + pub plugin: Arc<Mutex<Option<PathBuf>>>, + pub exit_status: i32, + } + + impl OpenVpnBuilder for TestOpenVpnBuilder { + type ProcessHandle = TestProcessHandle; + + fn plugin<P: AsRef<Path>>(&mut self, path: P, _args: Vec<String>) -> &mut Self { + *self.plugin.lock().unwrap() = Some(path.as_ref().to_path_buf()); + self + } + + fn start(&self) -> io::Result<Self::ProcessHandle> { + Ok(TestProcessHandle(self.exit_status)) + } + } + + struct TestProcessHandle(i32); + + impl ProcessHandle for TestProcessHandle { + #[cfg(unix)] + fn wait(&self) -> io::Result<ExitStatus> { + use std::os::unix::process::ExitStatusExt; + Ok(ExitStatus::from_raw(self.0)) + } + + #[cfg(windows)] + fn wait(&self) -> io::Result<ExitStatus> { + use std::os::windows::process::ExitStatusExt; + Ok(ExitStatus::from_raw(self.0 as u32)) + } + + fn kill(&self) -> io::Result<()> { + Ok(()) + } + } #[test] - #[ignore] - fn openvpn_event_dispatcher_server() { - let server = OpenVpnEventDispatcher::start( - |event, env| { - println!("event: {:?}. env: {:?}", event, env); - }, - ) - .unwrap(); - println!("plugin server listening on {}", server.address()); - server.wait().unwrap(); + fn plugin() { + let builder = TestOpenVpnBuilder::default(); + OpenVpnMonitor::new_internal(builder.clone(), |_, _| {}, "./my_test_plugin").unwrap(); + assert_eq!( + Some(PathBuf::from("./my_test_plugin")), + *builder.plugin.lock().unwrap() + ); + } + + #[test] + fn exit_successfully() { + let mut builder = TestOpenVpnBuilder::default(); + builder.exit_status = 0; + let testee = OpenVpnMonitor::new_internal(builder, |_, _| {}, "").unwrap(); + assert!(testee.wait().is_ok()); + } + + #[test] + fn exit_error() { + let mut builder = TestOpenVpnBuilder::default(); + builder.exit_status = 1; + let testee = OpenVpnMonitor::new_internal(builder, |_, _| {}, "").unwrap(); + assert!(testee.wait().is_err()); + } + + #[test] + fn wait_closed() { + let mut builder = TestOpenVpnBuilder::default(); + builder.exit_status = 1; + let testee = OpenVpnMonitor::new_internal(builder, |_, _| {}, "").unwrap(); + testee.close_handle().close().unwrap(); + assert!(testee.wait().is_ok()); } } |
