From a29c408583755f76d4209001e541561d11ee5095 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Wed, 24 Apr 2024 14:39:56 +0200 Subject: [PATCH] cli: make nested/out-of-jay run-privileged a no-op --- src/acceptor.rs | 2 +- src/cli/run_privileged.rs | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/acceptor.rs b/src/acceptor.rs index a73fca68..b8d584d0 100644 --- a/src/acceptor.rs +++ b/src/acceptor.rs @@ -46,7 +46,6 @@ struct AllocatedSocket { lock_path: Ustring, _lock_fd: OwnedFd, // /run/user/1000/wayland-x.jay - #[cfg_attr(not(feature = "it"), allow(dead_code))] secure_path: Ustring, secure: Rc, } @@ -55,6 +54,7 @@ impl Drop for AllocatedSocket { fn drop(&mut self) { let _ = uapi::unlink(&self.path); let _ = uapi::unlink(&self.lock_path); + let _ = uapi::unlink(&self.secure_path); } } diff --git a/src/cli/run_privileged.rs b/src/cli/run_privileged.rs index 21370195..3e7e4157 100644 --- a/src/cli/run_privileged.rs +++ b/src/cli/run_privileged.rs @@ -3,19 +3,26 @@ use { cli::{GlobalArgs, RunPrivilegedArgs}, compositor::WAYLAND_DISPLAY, logger::Logger, - utils::{errorfmt::ErrorFmt, oserror::OsError}, + utils::{errorfmt::ErrorFmt, oserror::OsError, xrd::xrd}, }, + std::path::PathBuf, uapi::UstrPtr, }; pub fn main(global: GlobalArgs, args: RunPrivilegedArgs) { Logger::install_stderr(global.log_level.into()); - let mut wd = match std::env::var(WAYLAND_DISPLAY) { - Ok(v) => v, - _ => fatal!("{} is not set", WAYLAND_DISPLAY), - }; - wd.push_str(".jay"); - std::env::set_var(WAYLAND_DISPLAY, &wd); + if let Some(xrd) = xrd() { + let mut wd = match std::env::var(WAYLAND_DISPLAY) { + Ok(v) => v, + _ => fatal!("{} is not set", WAYLAND_DISPLAY), + }; + wd.push_str(".jay"); + let mut path = PathBuf::from(xrd); + path.push(&wd); + if path.exists() { + std::env::set_var(WAYLAND_DISPLAY, &wd); + } + } let mut argv = UstrPtr::new(); for arg in &args.program { argv.push(arg.as_str());