From 71a9c390e77d09e3f3d9c3ec56436e5f674b9842 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Thu, 1 Jul 2021 13:01:22 +0200 Subject: [PATCH] Respect XDG_RUNTIME_DIR for /path/to/swayr-%s.sock /run may not exist outside of systemd distributions. Instead of guessing rely on XDG_RUNTIME_DIR and fall back to /tmp. XDG_RUNTIME_DIR is always defined under Wayland, so the fallback would only be triggered if swayr is used from X11 or VT/serial console. --- Cargo.lock | 20 -------------------- Cargo.toml | 1 - src/util.rs | 11 +++++++++-- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce60283..1981bb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -146,15 +146,6 @@ version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" -[[package]] -name = "log" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" -dependencies = [ - "cfg-if", -] - [[package]] name = "os_str_bytes" version = "2.4.0" @@ -297,7 +288,6 @@ dependencies = [ "serde_json", "swayipc", "toml", - "users", ] [[package]] @@ -376,16 +366,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" -[[package]] -name = "users" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032" -dependencies = [ - "libc", - "log", -] - [[package]] name = "vec_map" version = "0.8.2" diff --git a/Cargo.toml b/Cargo.toml index 3730ff8..5fadc46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ edition = "2018" serde = { version = "1.0.126", features = ["derive"] } serde_json = "1.0.64" clap = "3.0.0-beta.2" -users = "0.11.0" swayipc = "3.0.0-alpha.3" toml = "0.5.8" directories = "3.0" diff --git a/src/util.rs b/src/util.rs index 2029513..bab5592 100644 --- a/src/util.rs +++ b/src/util.rs @@ -23,9 +23,16 @@ use std::process as proc; pub fn get_swayr_socket_path() -> String { let wayland_display = std::env::var("WAYLAND_DISPLAY"); + let xdg_runtime_dir = std::env::var("XDG_RUNTIME_DIR"); format!( - "/run/user/{}/swayr-{}.sock", - users::get_current_uid(), + "{}/swayr-{}.sock", + match xdg_runtime_dir { + Ok(val) => val, + Err(_e) => { + eprintln!("Couldn't get XDG_RUNTIME_DIR!"); + String::from("/tmp") + } + }, match wayland_display { Ok(val) => val, Err(_e) => {