summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-08-01 09:23:25 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-08-01 09:23:25 -0300
commit0abcde1cac8db5bd86080ee92a39521d3c2bd13c (patch)
tree6c19c1bf644cdb6a34ef5b4e2f2790f8567d298d
parent1c3dc0ad052269606332a52a0c8f7290c7056904 (diff)
parentc372812fc04ea8f9a5a6d3b9e49ff4e665a6bb7f (diff)
downloadmullvadvpn-0abcde1cac8db5bd86080ee92a39521d3c2bd13c.tar.xz
mullvadvpn-0abcde1cac8db5bd86080ee92a39521d3c2bd13c.zip
Merge branch 'fallback-to-os-release-file'
-rw-r--r--Cargo.lock25
-rw-r--r--mullvad-problem-report/Cargo.toml3
-rw-r--r--mullvad-problem-report/src/main.rs58
3 files changed, 81 insertions, 5 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 5579f9ba7b..7dfa8c604b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -886,6 +886,7 @@ dependencies = [
"mullvad-paths 0.1.0",
"mullvad-rpc 0.1.0",
"regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rs-release 0.1.7 (git+https://github.com/mullvad/rs-release?branch=snailquote-unescape)",
"uuid 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"windres 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1260,6 +1261,14 @@ dependencies = [
]
[[package]]
+name = "rs-release"
+version = "0.1.7"
+source = "git+https://github.com/mullvad/rs-release?branch=snailquote-unescape#88b2afb04c3b2b1b76f27d8b8d48cd52facd292a"
+dependencies = [
+ "snailquote 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "rustc-demangle"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1389,6 +1398,14 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "snailquote"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "unicode_categories 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "stable_deref_trait"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1795,6 +1812,11 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "unicode_categories"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "unreachable"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2084,6 +2106,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum relay 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1576e382688d7e9deecea24417e350d3062d97e32e45d70b1cde65994ff1489a"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum resolv-conf 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c62bd95a41841efdf7fca2ae9951e64a8d8eae7e5da196d8ce489a2241491a92"
+"checksum rs-release 0.1.7 (git+https://github.com/mullvad/rs-release?branch=snailquote-unescape)" = "<none>"
"checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649"
"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f"
"checksum same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfb6eded0b06a0b512c8ddbcf04089138c9b4362c2f696f3c3d76039d68f3637"
@@ -2103,6 +2126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fdeff4cd9ecff59ec7e3744cbca73dfe5ac35c2aedb2cfba8a1c715a18912e9d"
"checksum smallvec 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4c8cbcd6df1e117c2210e13ab5109635ad68a929fcbb8964dc965b76cb5ee013"
"checksum smallvec 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03dab98ab5ded3a8b43b2c80751194608d0b2aa0f1d46cf95d1c35e192844aa7"
+"checksum snailquote 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "abe8023ba7352ceed1705c51d96f503c34eaec3142fa60e0591dce0fb3f81e03"
"checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b"
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
@@ -2139,6 +2163,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
+"checksum unicode_categories 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f808aadd8cfec6ef90e4a14eb46f24511824d1ac596b9682703c87056c8678b7"
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
diff --git a/mullvad-problem-report/Cargo.toml b/mullvad-problem-report/Cargo.toml
index d6aa9986f6..592c2f0ace 100644
--- a/mullvad-problem-report/Cargo.toml
+++ b/mullvad-problem-report/Cargo.toml
@@ -20,5 +20,8 @@ uuid = { version = "0.6", features = ["v4"] }
mullvad-paths = { path = "../mullvad-paths" }
mullvad-rpc = { path = "../mullvad-rpc" }
+[target.'cfg(target_os = "linux")'.dependencies]
+rs-release = { git = "https://github.com/mullvad/rs-release", branch = "snailquote-unescape" }
+
[target.'cfg(windows)'.build-dependencies]
windres = "0.1"
diff --git a/mullvad-problem-report/src/main.rs b/mullvad-problem-report/src/main.rs
index 1d0e9f92f8..d43cfc8a4b 100644
--- a/mullvad-problem-report/src/main.rs
+++ b/mullvad-problem-report/src/main.rs
@@ -14,6 +14,8 @@ extern crate error_chain;
#[macro_use]
extern crate lazy_static;
extern crate regex;
+#[cfg(target_os = "linux")]
+extern crate rs_release;
extern crate uuid;
extern crate mullvad_paths;
@@ -472,11 +474,57 @@ fn product_version() -> &'static str {
#[cfg(target_os = "linux")]
fn os_version() -> String {
- format!(
- "Linux, {}",
- command_stdout_lossy("lsb_release", &["-ds"])
- .unwrap_or(String::from("[Failed to get LSB release]"))
- )
+ // The OS version information is obtained first from the os-release file. If that information
+ // is incomplete or unavailable, an attempt is made to obtain the version information from the
+ // lsb_release command. If that fails, any partial information from os-release is used if
+ // available, or a fallback message if reading from the os-release file produced no version
+ // information.
+ let os_version = read_os_release_file().unwrap_or_else(|incomplete_info| {
+ parse_lsb_release().unwrap_or_else(|| {
+ incomplete_info
+ .unwrap_or_else(|| String::from("[failed to get Linux distribution/version]"))
+ })
+ });
+
+ format!("Linux, {}", os_version)
+}
+
+#[cfg(target_os = "linux")]
+fn read_os_release_file() -> std::result::Result<String, Option<String>> {
+ let mut os_release_info = rs_release::get_os_release().map_err(|_| None)?;
+ let os_name = os_release_info.remove("NAME");
+ let os_version = os_release_info.remove("VERSION");
+
+ if os_name.is_some() || os_version.is_some() {
+ let full_info_available = os_name.is_some() && os_version.is_some();
+
+ let gathered_info = format!(
+ "{} {}",
+ os_name.unwrap_or_else(|| "[unknown distribution]".to_owned()),
+ os_version.unwrap_or_else(|| "[unknown version]".to_owned())
+ );
+
+ if full_info_available {
+ Ok(gathered_info)
+ } else {
+ // Partial version information
+ Err(Some(gathered_info))
+ }
+ } else {
+ // No information was obtained
+ Err(None)
+ }
+}
+
+#[cfg(target_os = "linux")]
+fn parse_lsb_release() -> Option<String> {
+ command_stdout_lossy("lsb_release", &["-ds"]).and_then(|output| {
+ if output.is_empty() {
+ None
+ } else {
+ Some(output)
+ }
+ })
}
#[cfg(target_os = "macos")]