Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
phiresky opened this issue May 8, 2021 · 0 comments
Open

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

phiresky opened this issue May 8, 2021 · 0 comments

Comments

@phiresky
Copy link

phiresky commented May 8, 2021

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant