mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2025-01-18 22:26:12 +01:00
Use $XDG_RUNTIME_DIR
for socket
This commit is contained in:
parent
4f00a3c414
commit
50716a9168
2 changed files with 12 additions and 13 deletions
|
@ -50,6 +50,7 @@ use smithay::reexports::calloop::{
|
|||
use self::msg::{Msg, OutgoingMsg};
|
||||
|
||||
pub const DEFAULT_SOCKET_DIR: &str = "/tmp";
|
||||
pub const SOCKET_NAME: &str = "pinnacle_socket";
|
||||
|
||||
fn handle_client(
|
||||
mut stream: UnixStream,
|
||||
|
@ -90,7 +91,7 @@ impl PinnacleSocketSource {
|
|||
/// Create a loop source that listens for connections to the provided socket_dir.
|
||||
/// This will also set PINNACLE_SOCKET for use in API implementations.
|
||||
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 exists {
|
||||
|
|
22
src/state.rs
22
src/state.rs
|
@ -208,24 +208,22 @@ impl State {
|
|||
|
||||
let metaconfig = crate::metaconfig::parse(&config_dir)?;
|
||||
|
||||
let socket_dir = {
|
||||
let dir_string = shellexpand::full(
|
||||
metaconfig
|
||||
.socket_dir
|
||||
.as_deref()
|
||||
.unwrap_or(DEFAULT_SOCKET_DIR),
|
||||
)?
|
||||
.to_string();
|
||||
|
||||
// If a socket is provided in the metaconfig, use it.
|
||||
let socket_dir = if let Some(socket_dir) = &metaconfig.socket_dir {
|
||||
// cd into the metaconfig dir and canonicalize to preserve relative paths
|
||||
// like ./dir/here
|
||||
let current_dir = std::env::current_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)?;
|
||||
|
||||
pathbuf
|
||||
socket_dir
|
||||
} 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)
|
||||
|
|
Loading…
Reference in a new issue