Use $XDG_RUNTIME_DIR for socket

This commit is contained in:
Ottatop 2023-09-11 03:22:51 -05:00
parent 4f00a3c414
commit 50716a9168
2 changed files with 12 additions and 13 deletions

View file

@ -50,6 +50,7 @@ use smithay::reexports::calloop::{
use self::msg::{Msg, OutgoingMsg}; use self::msg::{Msg, OutgoingMsg};
pub const DEFAULT_SOCKET_DIR: &str = "/tmp"; pub const DEFAULT_SOCKET_DIR: &str = "/tmp";
pub const SOCKET_NAME: &str = "pinnacle_socket";
fn handle_client( fn handle_client(
mut stream: UnixStream, mut stream: UnixStream,
@ -90,7 +91,7 @@ impl PinnacleSocketSource {
/// Create a loop source that listens for connections to the provided socket_dir. /// Create a loop source that listens for connections to the provided socket_dir.
/// This will also set PINNACLE_SOCKET for use in API implementations. /// This will also set PINNACLE_SOCKET for use in API implementations.
pub fn new(sender: Sender<Msg>, socket_dir: &Path) -> anyhow::Result<Self> { pub fn new(sender: Sender<Msg>, socket_dir: &Path) -> anyhow::Result<Self> {
let socket_path = socket_dir.join("pinnacle_socket"); let socket_path = socket_dir.join(SOCKET_NAME);
if let Ok(exists) = socket_path.try_exists() { if let Ok(exists) = socket_path.try_exists() {
if exists { if exists {

View file

@ -208,24 +208,22 @@ impl State {
let metaconfig = crate::metaconfig::parse(&config_dir)?; let metaconfig = crate::metaconfig::parse(&config_dir)?;
let socket_dir = { // If a socket is provided in the metaconfig, use it.
let dir_string = shellexpand::full( let socket_dir = if let Some(socket_dir) = &metaconfig.socket_dir {
metaconfig
.socket_dir
.as_deref()
.unwrap_or(DEFAULT_SOCKET_DIR),
)?
.to_string();
// cd into the metaconfig dir and canonicalize to preserve relative paths // cd into the metaconfig dir and canonicalize to preserve relative paths
// like ./dir/here // like ./dir/here
let current_dir = std::env::current_dir()?; let current_dir = std::env::current_dir()?;
std::env::set_current_dir(&config_dir)?; std::env::set_current_dir(&config_dir)?;
let pathbuf = PathBuf::from(&dir_string).canonicalize()?; let socket_dir = PathBuf::from(socket_dir).canonicalize()?;
std::env::set_current_dir(current_dir)?; std::env::set_current_dir(current_dir)?;
socket_dir
pathbuf } else {
// Otherwise, use $XDG_RUNTIME_DIR. If that doesn't exist, use /tmp.
crate::XDG_BASE_DIRS
.get_runtime_directory()
.cloned()
.unwrap_or(PathBuf::from(crate::api::DEFAULT_SOCKET_DIR))
}; };
let socket_source = PinnacleSocketSource::new(tx_channel, &socket_dir) let socket_source = PinnacleSocketSource::new(tx_channel, &socket_dir)