From 0dd510dbc3a5b6e888abcc104ae8c4a4eeb1e42b Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 25 Jun 2026 17:14:07 +0900 Subject: feat(shim): implement stream_select/stream_set_blocking via libc Add fcntl/select extern "C" declarations and a PhpResource::raw_fd seam so the symfony Process pipe loop can read a live child's stdout/stderr. Fix fread on a non-blocking fd (WouldBlock -> "") and the Process null-cwd default. Real subprocess output capture now works; un-ignore the process_executor tests. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe-php-shim/src/lib.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'crates/shirabe-php-shim/src/lib.rs') diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index 113c9d7..8c8073f 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -349,6 +349,32 @@ pub enum PhpResource { Process(std::rc::Rc>), } +impl PhpResource { + /// Returns the underlying OS file descriptor backing this resource, when it has one. + /// Used by `stream_set_blocking`/`stream_select` to drive `fcntl(2)`/`select(2)`. In-memory + /// streams (`php://memory`/`php://temp`) and process handles have no fd and return `None`. + pub(crate) fn raw_fd(&self) -> Option { + use std::os::unix::io::AsRawFd; + match self { + PhpResource::Stdin => Some(std::io::stdin().as_raw_fd()), + PhpResource::Stdout => Some(std::io::stdout().as_raw_fd()), + PhpResource::Stderr => Some(std::io::stderr().as_raw_fd()), + PhpResource::Process(_) => None, + PhpResource::Stream(state) => { + let state = state.borrow(); + if state.closed { + return None; + } + match &state.backing { + StreamBacking::File(f) => Some(f.as_raw_fd()), + StreamBacking::Pipe(p) => Some(p.as_raw_fd()), + StreamBacking::Memory(_) => None, + } + } + } + } +} + /// Combined capability of every seekable byte stream backing. Both `std::fs::File` /// and `std::io::Cursor>` satisfy it, so a stream can be driven uniformly. pub trait ReadWriteSeek: std::io::Read + std::io::Write + std::io::Seek {} @@ -420,6 +446,16 @@ impl std::io::Seek for ChildPipe { } } +impl std::os::unix::io::AsRawFd for ChildPipe { + fn as_raw_fd(&self) -> std::os::unix::io::RawFd { + match self { + ChildPipe::In(i) => i.as_raw_fd(), + ChildPipe::Out(o) => o.as_raw_fd(), + ChildPipe::Err(e) => e.as_raw_fd(), + } + } +} + #[derive(Debug)] pub struct StreamState { pub(crate) backing: StreamBacking, -- cgit v1.3.1