aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--crates/shirabe-php-shim/src/output.rs3
-rw-r--r--crates/shirabe-php-shim/src/process.rs13
-rw-r--r--crates/shirabe-php-shim/src/runtime.rs7
-rw-r--r--crates/shirabe-symfony-process/src/process.rs151
4 files changed, 17 insertions, 157 deletions
diff --git a/crates/shirabe-php-shim/src/output.rs b/crates/shirabe-php-shim/src/output.rs
index 698f3bf4..d4d83200 100644
--- a/crates/shirabe-php-shim/src/output.rs
+++ b/crates/shirabe-php-shim/src/output.rs
@@ -1,6 +1,5 @@
// PHP output buffering captures everything the interpreter would echo to stdout. The shim has no
-// general echo-to-buffer routing, and its only producer in Composer (`phpinfo`) depends on PHP
-// runtime configuration that is itself unmodeled, so a buffer here would silently capture nothing.
+// general echo-to-buffer routing, so a buffer here would silently capture nothing.
pub fn ob_start() -> bool {
todo!()
}
diff --git a/crates/shirabe-php-shim/src/process.rs b/crates/shirabe-php-shim/src/process.rs
index 2b380c60..b082f472 100644
--- a/crates/shirabe-php-shim/src/process.rs
+++ b/crates/shirabe-php-shim/src/process.rs
@@ -380,12 +380,7 @@ pub fn proc_terminate(process: &PhpResource, signal: i64) -> bool {
let Some(child) = state.child.as_ref() else {
return false;
};
- send_signal(child.id() as i32, signal)
-}
-
-/// Shared body of `proc_terminate` and `posix_kill`. Signal 0 is PHP's existence probe and is
-/// forwarded to `kill(2)` as such.
-fn send_signal(pid: i32, signal: i64) -> bool {
+ // Signal 0 is PHP's existence probe and is forwarded to `kill(2)` as such.
let signal = if signal == 0 {
None
} else {
@@ -394,7 +389,7 @@ fn send_signal(pid: i32, signal: i64) -> bool {
Err(_) => return false,
}
};
- nix::sys::signal::kill(nix::unistd::Pid::from_raw(pid), signal).is_ok()
+ nix::sys::signal::kill(nix::unistd::Pid::from_raw(child.id() as i32), signal).is_ok()
}
pub fn getmypid() -> i64 {
@@ -466,10 +461,6 @@ pub fn posix_isatty(stream: PhpResource) -> bool {
}
}
-pub fn posix_kill(pid: i64, signal: i64) -> bool {
- send_signal(pid as i32, signal)
-}
-
/// PHP `get_current_user()`: the name of the owner of the running script file. The Shirabe
/// executable takes the place of the script; PHP returns an empty string when the lookup fails.
pub fn get_current_user() -> String {
diff --git a/crates/shirabe-php-shim/src/runtime.rs b/crates/shirabe-php-shim/src/runtime.rs
index 86cbfd74..2b5e7155 100644
--- a/crates/shirabe-php-shim/src/runtime.rs
+++ b/crates/shirabe-php-shim/src/runtime.rs
@@ -27,7 +27,6 @@ pub const E_USER_NOTICE: i64 = 1024;
pub const E_DEPRECATED: i64 = 8192;
pub const E_USER_DEPRECATED: i64 = 16384;
-pub const INFO_GENERAL: i64 = 1;
pub const PHP_BINARY: &str = "";
// NOTE: &str matching in const expression does not compile for now.
@@ -366,12 +365,6 @@ pub fn ini_set(_varname: &str, _value: &str) -> Option<String> {
todo!()
}
-pub fn phpinfo(_what: i64) {
- // TODO(php-runtime): phpinfo() dumps the full PHP runtime configuration, which the shim does not
- // model.
- todo!()
-}
-
pub fn sapi_windows_vt100_support(_resource: &crate::PhpResource) -> bool {
// TODO(phase-c): Windows-only SAPI function; not defined on the non-Windows target this build
// models (function_exists reports it absent).
diff --git a/crates/shirabe-symfony-process/src/process.rs b/crates/shirabe-symfony-process/src/process.rs
index 1dfb5806..b7459d41 100644
--- a/crates/shirabe-symfony-process/src/process.rs
+++ b/crates/shirabe-symfony-process/src/process.rs
@@ -51,7 +51,6 @@ pub struct Process {
starttime: Option<f64>,
timeout: Option<f64>,
exitcode: Option<i64>,
- fallback_status: IndexMap<String, PhpMixed>,
process_information: Option<IndexMap<String, PhpMixed>>,
stdout: Option<PhpResource>,
stderr: Option<PhpResource>,
@@ -61,7 +60,6 @@ pub struct Process {
incremental_error_output_offset: i64,
tty: bool,
options: IndexMap<String, PhpMixed>,
- use_file_handles: bool,
process_pipes: Option<Box<dyn PipesInterface>>,
latest_signal: Option<i64>,
cached_exit_code: Option<i64>,
@@ -180,7 +178,6 @@ impl Process {
starttime: None,
timeout: None,
exitcode: None,
- fallback_status: IndexMap::new(),
process_information: None,
stdout: None,
stderr: None,
@@ -190,7 +187,6 @@ impl Process {
incremental_error_output_offset: 0,
tty: false,
options,
- use_file_handles: false,
process_pipes: None,
latest_signal: None,
cached_exit_code: None,
@@ -245,7 +241,6 @@ impl Process {
this.set_input(input)?;
this.set_timeout(timeout)?;
- this.use_file_handles = cfg!(windows);
Ok(this)
}
@@ -288,7 +283,7 @@ impl Process {
self.reset_process_data();
self.starttime = Some(shirabe_php_shim::microtime());
self.callback = Some(self.build_callback(callback));
- let mut descriptors = self.get_descriptors();
+ let descriptors = self.get_descriptors();
if !self.env.is_empty() {
// non-Windows: $env += $this->env;
@@ -320,17 +315,6 @@ impl Process {
if cfg!(windows) {
commandline = self.prepare_windows_command_line(&commandline, &mut env)?;
- } else if !self.use_file_handles && self.is_sigchild_enabled() {
- // last exit code is output on the fourth pipe and caught to work around --enable-sigchild
- descriptors.push(descriptor(&["pipe", "w"]));
-
- commandline = format!("{{ ({}) <&3 3<&- 3>/dev/null & }} 3<&0;", commandline);
- commandline.push_str(
- "pid=$!; echo $pid >&3; wait $pid 2>/dev/null; code=$?; echo $code >&3; exit $code",
- );
-
- // Workaround for the bug, when PTS functionality is enabled.
- let _pts_workaround = shirabe_php_shim::fopen("Process.php", "r");
}
let mut env_pairs: Vec<String> = Vec::new();
@@ -376,22 +360,6 @@ impl Process {
}
self.status = Self::STATUS_STARTED.to_string();
- if descriptors.len() > 3 {
- let pipe3 = self
- .process_pipes
- .as_ref()
- .unwrap()
- .pipes()
- .get(&3)
- .cloned();
- let pid = pipe3
- .and_then(|p| shirabe_php_shim::fgets(&p, None))
- .map(|s| s.trim().parse::<i64>().unwrap_or(0))
- .unwrap_or(0);
- self.fallback_status
- .insert("pid".to_string(), PhpMixed::Int(pid));
- }
-
if self.tty {
return Ok(());
}
@@ -515,19 +483,12 @@ impl Process {
pub fn get_term_signal(&mut self) -> anyhow::Result<i64> {
self.require_process_is_terminated("getTermSignal")?;
- let termsig = self
+ Ok(self
.process_information
.as_ref()
.and_then(|i| i.get("termsig"))
- .and_then(|v| v.as_int());
- if self.is_sigchild_enabled() && termsig == Some(-1) {
- return Err(RuntimeException::new(
- "This PHP has been compiled with --enable-sigchild. Term signal cannot be retrieved.".to_string(),
- )
- .into());
- }
-
- Ok(termsig.unwrap_or(0))
+ .and_then(|v| v.as_int())
+ .unwrap_or(0))
}
/// Checks if the process is currently running.
@@ -579,11 +540,6 @@ impl Process {
}
if self.is_running() {
- if self.fallback_status.contains_key("pid") {
- self.fallback_status.shift_remove("pid");
-
- return self.stop(0.0, signal);
- }
self.close();
}
@@ -814,43 +770,11 @@ impl Process {
self.read_pipes(running && blocking, !cfg!(windows) || !running);
- if !self.fallback_status.is_empty() && self.is_sigchild_enabled() {
- // processInformation = fallbackStatus + processInformation (fallback keys win)
- let mut merged = self.fallback_status.clone();
- for (k, v) in self.process_information.take().unwrap() {
- merged.entry(k).or_insert(v);
- }
- self.process_information = Some(merged);
- }
-
if !running {
self.close();
}
}
- /// Returns whether PHP has been compiled with the '--enable-sigchild' option or not.
- fn is_sigchild_enabled(&self) -> bool {
- static SIGCHILD: OnceLock<bool> = OnceLock::new();
-
- if let Some(v) = SIGCHILD.get() {
- return *v;
- }
-
- if !shirabe_php_shim::function_exists("phpinfo") {
- return *SIGCHILD.get_or_init(|| false);
- }
-
- shirabe_php_shim::ob_start();
- shirabe_php_shim::phpinfo(shirabe_php_shim::INFO_GENERAL);
-
- *SIGCHILD.get_or_init(|| {
- shirabe_php_shim::str_contains(
- &shirabe_php_shim::ob_get_clean().unwrap_or_default(),
- "--enable-sigchild",
- )
- })
- }
-
/// Reads pipes for the freshest output.
fn read_pipes_for_output(&mut self, caller: &str, blocking: bool) -> anyhow::Result<()> {
self.require_process_is_started(caller)?;
@@ -885,22 +809,15 @@ impl Process {
let mut callback = self.callback.take();
for (r#type, data) in result {
- if r#type != 3 {
- if let Some(cb) = callback.as_mut() {
- cb(
- self,
- if Self::STDOUT == r#type {
- Self::OUT
- } else {
- Self::ERR
- },
- &data,
- );
- }
- } else if !self.fallback_status.contains_key("signaled") {
- self.fallback_status.insert(
- "exitcode".to_string(),
- PhpMixed::Int(data.trim().parse().unwrap_or(0)),
+ if let Some(cb) = callback.as_mut() {
+ cb(
+ self,
+ if Self::STDOUT == r#type {
+ Self::OUT
+ } else {
+ Self::ERR
+ },
+ &data,
);
}
}
@@ -939,11 +856,6 @@ impl Process {
if signaled && termsig > 0 {
// if process has been signaled, no exitcode but a valid termsig, apply Unix convention
self.exitcode = Some(128 + termsig);
- } else if self.is_sigchild_enabled()
- && let Some(i) = self.process_information.as_mut()
- {
- i.insert("signaled".to_string(), PhpMixed::Bool(true));
- i.insert("termsig".to_string(), PhpMixed::Int(-1));
}
}
@@ -958,7 +870,6 @@ impl Process {
self.starttime = None;
self.callback = None;
self.exitcode = None;
- self.fallback_status = IndexMap::new();
self.process_information = None;
// php://temp is an in-memory stream; fopen never fails for it.
self.stdout = Some(
@@ -1012,33 +923,7 @@ impl Process {
return Ok(false);
}
} else {
- let ok;
- if !self.is_sigchild_enabled() {
- ok = shirabe_php_shim::proc_terminate(self.process.as_ref().unwrap(), signal);
- } else if shirabe_php_shim::function_exists("posix_kill") {
- ok = shirabe_php_shim::posix_kill(pid, signal);
- } else {
- let mut pipes = IndexMap::new();
- let opened = shirabe_php_shim::proc_open(
- &format!("kill -{} {}", signal, pid),
- &[
- Descriptor::Inherit,
- Descriptor::Inherit,
- descriptor(&["pipe", "w"]),
- ],
- &mut pipes,
- None,
- None,
- None,
- );
- ok = match opened {
- Ok(_) => pipes
- .get(&2)
- .and_then(|p| shirabe_php_shim::fgets(p, None))
- .is_none(),
- Err(_) => false,
- };
- }
+ let ok = shirabe_php_shim::proc_terminate(self.process.as_ref().unwrap(), signal);
if !ok {
if throw_exception {
return Err(RuntimeException::new(format!(
@@ -1053,14 +938,6 @@ impl Process {
}
self.latest_signal = Some(signal);
- self.fallback_status
- .insert("signaled".to_string(), PhpMixed::Bool(true));
- self.fallback_status
- .insert("exitcode".to_string(), PhpMixed::Int(-1));
- self.fallback_status.insert(
- "termsig".to_string(),
- PhpMixed::Int(self.latest_signal.unwrap()),
- );
Ok(true)
}