about summary refs log tree commit diff
path: root/src/facility
diff options
context:
space:
mode:
Diffstat (limited to 'src/facility')
-rw-r--r--src/facility/i3.rs38
1 files changed, 35 insertions, 3 deletions
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<Option<File>> {
+    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<Option<File>> {
-    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))
+  }
 }