diff options
| author | troido <troido@protonmail.com> | 2020-04-20 21:17:05 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-04-20 21:17:05 +0200 |
| commit | 2247665fad3017c41568714cea7b0d29d6b09a98 (patch) | |
| tree | 3ca59bb63290afe7ca1a5e71baa003ff2afcbaba /src/server/unixserver.rs | |
| parent | 9ffe36a5375a25601dcc528aa603fb1e679f9847 (diff) | |
added com cfg macros for detecting linux and bsd
Diffstat (limited to 'src/server/unixserver.rs')
| -rw-r--r-- | src/server/unixserver.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/server/unixserver.rs b/src/server/unixserver.rs index f3181de..fdb005f 100644 --- a/src/server/unixserver.rs +++ b/src/server/unixserver.rs @@ -94,17 +94,20 @@ impl Server for UnixServer { } } - + #[cfg(any(target_os = "linux", target_os = "android"))] fn get_name(&self, id: usize) -> Option<String> { let connection = self.connections.get(id)?; let fd = connection.stream.as_raw_fd(); - if let Ok(peercred) = getsockopt(fd, sockopt::PeerCredentials) { - let uid = peercred.uid(); - let user = users::get_user_by_uid(uid)?; - let name = user.name(); - Some(name.to_string_lossy().to_string()) - } else { None } + let peercred = getsockopt(fd, sockopt::PeerCredentials).ok()?; + let uid = peercred.uid(); + let user = users::get_user_by_uid(uid)?; + let name = user.name(); + Some(name.to_string_lossy().to_string()) + } + + #[cfg(not(any(target_os = "linux", target_os = "android")))] + fn get_name(&self, id: usize) -> Option<String> { + None } - } |
