Skip to content

Support unknown platforms (e.g. windows) #4

@phiresky

Description

@phiresky

Here's a simple patch:

diff --git a/src/lib.rs b/src/lib.rs
index ea221b3..b378b51 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -405,13 +406,15 @@ fn rand_int() -> AtomicUsize {
 }
 
 fn get_pid() -> u32 {
+    #[allow(unused_mut)]
     let mut pid = process::id();
 
     // If /proc/self/cpuset exists and is not /, we can assume that we are in a
     // form of container and use the content of cpuset xor-ed with the PID in
     // order get a reasonable machine global unique PID.
+    #[cfg(target_os = "linux")]
     match fs::read("/proc/self/cpuset") {
-        Err(_) => pid,
+        Err(_) => {},
 
         Ok(buff) => {
             let mut hasher = Hasher::new();
@@ -419,10 +422,10 @@ fn get_pid() -> u32 {
             let checksum = hasher.finalize();
 
             pid ^= checksum;
-
-            pid
         }
     }
+    
+    pid
 }
 
 fn read_machine_id() -> [u8; 3] {
@@ -461,6 +464,10 @@ fn platform_machine_id() -> Result<String, io::Error> {
 
     Ok(contents)
 }
+#[cfg(not(target_os = "linux"))]
+fn platform_machine_id() -> Result<String, io::Error> {
+    Err(io::Error::new(io::ErrorKind::NotFound, "unsupported"))
+}
 
 fn hostname() -> String {
     gethostname()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions