From 7465b56cc11bb4b17ba8d994142da0b74cbb8c7e Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Tue, 24 Nov 2026 01:20:34 -0700 Subject: actually open the i3 socket now yay Force-Push: yes Change-Id: I93f991f29d71f91b03a9a43179c59cf4d6b64d70 --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 1 + src/facility/i3.rs | 24 +++++++++++++++--------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0edf3ea..ccf64c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,6 +68,17 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "async-net" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b948000fad4873c1c9339d60f2623323a0cfd3816e5181033c6a5cb68b2accf7" +dependencies = [ + "async-io", + "blocking", + "futures-lite", +] + [[package]] name = "async-task" version = "4.7.1" @@ -335,6 +346,7 @@ dependencies = [ "async-executor", "async-fs", "async-io", + "async-net", "bitflags", "futures-lite", "json-event-parser", diff --git a/Cargo.toml b/Cargo.toml index 8e91a58..72f5d3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2024" async-channel = "2.0.0" async-fs = "2.0.0" async-io = "2.1.0" +async-net = "2.0.0" libc = "0.2.191" json-event-parser = "0.2.3" futures-lite = "2.0.0" diff --git a/src/facility/i3.rs b/src/facility/i3.rs index 4b91b02..c2f9878 100644 --- a/src/facility/i3.rs +++ b/src/facility/i3.rs @@ -6,13 +6,14 @@ use crate::xdg::xdg_runtime_directory; use std::any::Any; use std::path::{ Path, PathBuf }; -use async_fs::{ metadata, read_dir, File, OpenOptions }; +use async_fs::{ metadata, read_dir }; use async_fs::unix::FileTypeExt; +use async_net::unix::UnixStream; use futures_lite::StreamExt; pub struct I3 { - socket: File, + socket: UnixStream, } @@ -37,7 +38,7 @@ impl CreatableFacility for I3 { } impl I3 { - async fn find_socket() -> Result { + async fn find_socket() -> Result { /* We save most errors for the end, because they aren't really errors if * a subsequent attempt succeeds. */ @@ -97,7 +98,7 @@ impl I3 { * for subdirectories with names having a specific pattern. Do that. */ async fn try_tmp_directory(path: &Path, username: &str) - -> Result> + -> Result> { let mut directory = read_dir(path).await?; @@ -135,7 +136,7 @@ impl I3 { * The directory iteration logic is a lot like that for try_tmp_directory(). * In principle, it could make sense to write a helper. */ - async fn try_socket_directory(path: &Path) -> Result> { + async fn try_socket_directory(path: &Path) -> Result> { let mut directory = read_dir(path).await?; while let Some(entry) = directory.try_next().await? { @@ -165,15 +166,20 @@ impl I3 { } /* If we have a candidate full path to an i3 socket, see if it works. */ - async fn try_socket_path(path: &Path) -> Result> { + async fn try_socket_path(path: &Path) -> Result> { /* Do follow symlinks, for the socket check. */ if !metadata(path).await?.file_type().is_socket() { return Ok(None); } - /* Unix-domain sockets don't use open(), despite appearing in the filesystem. TODO */ - let socket = OpenOptions::new().read(true).write(true).open(path).await?; - println!("got i3 socket {:?}", path); + /* Unix-domain sockets don't use open(), despite appearing in the + * filesystem. If you think about it, that makes sense: Each process that + * opens it gets its own send/receive pair. It's not like a pipe. + */ + let socket = UnixStream::connect(path).await?; + + println!("Found i3 socket {}", path.display()); + Ok(Some(socket)) } } -- cgit 1.4.1