From 61120e03d030f14126163aa02fd78989e83aa394 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Mon, 23 Nov 2026 23:13:40 -0700 Subject: more progress on finding the i3 socket Force-Push: yes Change-Id: Iacdfbe0b824b0ebe8d53943cb1b480985f787af2 --- src/facility/i3.rs | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'src/facility') diff --git a/src/facility/i3.rs b/src/facility/i3.rs index 7ee29dc..2911b4b 100644 --- a/src/facility/i3.rs +++ b/src/facility/i3.rs @@ -5,7 +5,9 @@ use crate::xdg::xdg_runtime_directory; use std::any::Any; use std::path::{ Path, PathBuf }; -use async_fs::File; +use async_fs::{ metadata, read_dir, File }; +use async_fs::unix::FileTypeExt; +use futures_lite::StreamExt; pub struct I3 { @@ -83,12 +85,42 @@ impl I3 { } async fn try_socket_directory(path: &Path) -> Result> { + let mut directory = read_dir(path).await?; + + while let Some(entry) = directory.try_next().await? { + /* Do not follow symlinks for the name check. + * + * Note also that if the name isn't valid Unicode, it doesn't match the + * pattern anyway. + */ + if let Some(name) = entry.file_name().to_str() { + let prefix = "ipc-socket."; + if name.starts_with(prefix) { + let tail = &name[prefix.len() ..]; + + if tail.len() > 0 + && tail.chars().all(|c| { c.is_ascii_digit() }) + { + let full_path = path.join(name); + if let Some(socket) = Self::try_socket_path(&full_path).await? { + return Ok(Some(socket)); + } + } + } + } + } + Ok(None) } async fn try_socket_path(path: &Path) -> Result> { - Ok(None) - } + /* Do follow symlinks, for the socket check. */ + if !metadata(path).await?.file_type().is_socket() { + return Ok(None); + } + let socket = File::open(path).await?; + Ok(Some(socket)) + } } -- cgit 1.4.1