Skip to content

Commit b9e8078

Browse files
committed
Fixed availability check for Linux Telemetry providers
1 parent 085cdbc commit b9e8078

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

core/src/target/linux.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,47 @@ use regex::Regex;
99
use std::{fs, process, str};
1010
use std::io::Read;
1111

12+
#[derive(Eq, PartialEq)]
13+
pub enum LinuxFlavour {
14+
Centos,
15+
Debian,
16+
Fedora,
17+
Redhat,
18+
Ubuntu,
19+
NixOs,
20+
}
21+
22+
pub fn fingerprint_os() -> Option<LinuxFlavour> {
23+
// @todo Cache this result
24+
25+
// CentOS
26+
if let Ok(_) = fs::metadata("/etc/centos-release") {
27+
Some(LinuxFlavour::Centos)
28+
}
29+
// Ubuntu
30+
else if let Ok(_) = fs::metadata("/etc/lsb-release") {
31+
Some(LinuxFlavour::Ubuntu)
32+
}
33+
// Debian
34+
else if let Ok(_) = fs::metadata("/etc/debian_version") {
35+
Some(LinuxFlavour::Debian)
36+
}
37+
// Fedora
38+
else if let Ok(_) = fs::metadata("/etc/fedora-release") {
39+
Some(LinuxFlavour::Fedora)
40+
}
41+
// RedHat
42+
else if let Ok(_) = fs::metadata("/etc/redhat-release") {
43+
Some(LinuxFlavour::Redhat)
44+
}
45+
// NixOS
46+
else if let Ok(_) = fs::metadata("/etc/nixos/configuration.nix") {
47+
Some(LinuxFlavour::NixOs)
48+
} else {
49+
None
50+
}
51+
}
52+
1253
pub fn cpu_vendor() -> Result<String> {
1354
get_cpu_item("vendor_id")
1455
}

core/src/telemetry/providers/centos.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use host::*;
1111
use pnet::datalink::interfaces;
1212
use std::{env, str};
1313
use target::{default, linux, redhat};
14+
use target::linux::LinuxFlavour;
1415
use telemetry::{Cpu, Os, OsFamily, OsPlatform, Telemetry, TelemetryProvider, serializable};
1516

1617
pub struct Centos;
@@ -36,7 +37,7 @@ impl <'de>ExecutableProvider<'de> for RemoteProvider {
3637
impl TelemetryProvider for Centos {
3738
fn available(host: &Host) -> bool {
3839
if host.is_local() {
39-
cfg!(target_os="linux")
40+
cfg!(target_os="linux") && linux::fingerprint_os() == Some(LinuxFlavour::Centos)
4041
} else {
4142
unimplemented!();
4243
// let r = RemoteProvider::Available;

core/src/telemetry/providers/debian.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use host::*;
1111
use pnet::datalink::interfaces;
1212
use std::{env, process, str};
1313
use target::{default, linux};
14+
use target::linux::LinuxFlavour;
1415
use telemetry::{Cpu, Os, OsFamily, OsPlatform, Telemetry, TelemetryProvider, serializable};
1516

1617
pub struct Debian;
@@ -36,7 +37,7 @@ impl <'de>ExecutableProvider<'de> for RemoteProvider {
3637
impl TelemetryProvider for Debian {
3738
fn available(host: &Host) -> bool {
3839
if host.is_local() {
39-
cfg!(target_os="linux")
40+
cfg!(target_os="linux") && linux::fingerprint_os() == Some(LinuxFlavour::Debian)
4041
} else {
4142
unimplemented!();
4243
// let r = RemoteProvider::Available;

0 commit comments

Comments
 (0)