summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs5
-rw-r--r--src/server/address.rs8
-rw-r--r--src/server/unixserver.rs19
3 files changed, 22 insertions, 10 deletions
diff --git a/src/main.rs b/src/main.rs
index 261d678..3682e7c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -66,7 +66,10 @@ fn main(){
let config = config::Config::from_args();
let adresses = config.address
- .unwrap_or(vec!["abstract:rustifarm".parse().unwrap(), "inet:127.0.0.1:1234".parse().unwrap()]);
+ .unwrap_or(vec![
+ (if cfg!(target_os = "linux") {"abstract:rustifarm"} else {"unix:/tmp/rustifarm"}).parse().unwrap(),
+ "inet:127.0.0.1:1234".parse().unwrap()
+ ]);
println!("adresses: {:?}", adresses);
let servers: Vec<Box<dyn Server>> =
adresses
diff --git a/src/server/address.rs b/src/server/address.rs
index 6256f41..64aea2d 100644
--- a/src/server/address.rs
+++ b/src/server/address.rs
@@ -38,7 +38,13 @@ impl FromStr for Address {
match typename {
"inet" => Ok(Address::Inet(text.parse()?)),
"unix" => Ok(Address::Unix(PathBuf::new().join(text))),
- "abstract" => Ok(Address::Unix(PathBuf::new().join(&format!("\0{}", text)))),
+ "abstract" => {
+ if cfg!(target_os = "linux") {
+ Ok(Address::Unix(PathBuf::new().join(&format!("\0{}", text))))
+ } else {
+ Err(aerr!("abstract adresses are only for linux"))
+ }
+ }
_ => Err(aerr!("'{}' is not a valid address type", typename))
}
}
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
}
-
}