diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-02 09:39:04 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-02 09:39:04 +0900 |
| commit | c241931303448f9449051ea2080c1b65561066f2 (patch) | |
| tree | 2bca8a0a4d009ed18d68ce427a0c7be64af42edd /crates/shirabe-php-shim/src/lib.rs | |
| parent | 2c3373a7466c31f5cce7c2867c00a91afaa8e128 (diff) | |
| download | php-shirabe-c241931303448f9449051ea2080c1b65561066f2.tar.gz php-shirabe-c241931303448f9449051ea2080c1b65561066f2.tar.zst php-shirabe-c241931303448f9449051ea2080c1b65561066f2.zip | |
feat(php-shim): implement syscall-backed functions via the nix crate
Several shim functions were left as todo!() because the standard library
exposes no equivalent and no syscall crate was available. Adding nix
unblocks them:
- proc_open now wires descriptors beyond stderr, creating the pipe itself
and installing the child end with dup2(2) from pre_exec
- proc_terminate and posix_kill deliver arbitrary signals via kill(2)
- get_current_user reports the owner of the running executable
- php_uname answers every mode from uname(2) instead of only "s" and "r"
It also closes gaps that were previously approximated:
- fstat stats the stdio streams and pipes rather than reporting failure
- touch stamps mtime/atime on an existing path, including directories
- is_writable/is_executable use access(2) instead of permission bits
- umask falls back to the read-modify-write umask(2) off Linux
The hand-written repr(C) structs and extern "C" declarations for getpwuid,
utime, statvfs, fcntl and select are replaced by their nix wrappers, which
in turn lets disk_free_space drop its Linux-only cfg.
cli_set_process_title, setproctitle and the pcntl_signal pair stay as
todo!(): the first two need access to the process's own argv block, and
the latter two depend on the signal-handling subsystem rather than on
sigaction(2) itself.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim/src/lib.rs')
| -rw-r--r-- | crates/shirabe-php-shim/src/lib.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index 1d9f27e4..93b2e430 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -423,6 +423,10 @@ pub enum ChildPipe { In(std::process::ChildStdin), Out(std::process::ChildStdout), Err(std::process::ChildStderr), + /// The parent end of a pipe wired to a child descriptor beyond stderr. `std::process::Child` + /// exposes no typed handle for those, so the raw end is kept as a file. Its direction is + /// carried by the owning `StreamState`'s `readable`/`writable` flags. + Extra(std::fs::File), } impl std::io::Read for ChildPipe { @@ -430,6 +434,7 @@ impl std::io::Read for ChildPipe { match self { ChildPipe::Out(o) => o.read(buf), ChildPipe::Err(e) => e.read(buf), + ChildPipe::Extra(f) => f.read(buf), ChildPipe::In(_) => Err(std::io::Error::from(std::io::ErrorKind::Unsupported)), } } @@ -439,6 +444,7 @@ impl std::io::Write for ChildPipe { fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { match self { ChildPipe::In(i) => i.write(buf), + ChildPipe::Extra(f) => f.write(buf), ChildPipe::Out(_) | ChildPipe::Err(_) => { Err(std::io::Error::from(std::io::ErrorKind::Unsupported)) } @@ -448,6 +454,7 @@ impl std::io::Write for ChildPipe { fn flush(&mut self) -> std::io::Result<()> { match self { ChildPipe::In(i) => i.flush(), + ChildPipe::Extra(f) => f.flush(), ChildPipe::Out(_) | ChildPipe::Err(_) => Ok(()), } } @@ -465,6 +472,7 @@ impl std::os::unix::io::AsRawFd for ChildPipe { ChildPipe::In(i) => i.as_raw_fd(), ChildPipe::Out(o) => o.as_raw_fd(), ChildPipe::Err(e) => e.as_raw_fd(), + ChildPipe::Extra(f) => f.as_raw_fd(), } } } |
