Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions ext/standard/proc_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,13 @@ static void proc_open_rsrc_dtor(zend_resource *rsrc)

if (wait_pid <= 0) {
FG(pclose_ret) = -1;
} else if (WIFEXITED(wstatus)) {
FG(pclose_ret) = WEXITSTATUS(wstatus);
} else if (WIFSIGNALED(wstatus)) {
/* Follow the bash/shell convention: 128 + signal number */
FG(pclose_ret) = 128 + WTERMSIG(wstatus);
} else {
if (WIFEXITED(wstatus)) {
wstatus = WEXITSTATUS(wstatus);
}
FG(pclose_ret) = wstatus;
FG(pclose_ret) = -1;
}

#else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--TEST--
proc_close() returns 128+signal when child is killed by a signal
--SKIPIF--
<?php
if (PHP_OS_FAMILY === 'Windows') die('skip Not for Windows');
if (!is_executable('/bin/sh')) die('skip /bin/sh not available');
?>
--FILE--
<?php

// Shell that kills itself with SIGKILL (9) — cannot be caught
$process = proc_open(
['/bin/sh', '-c', 'kill -9 $$'],
[['pipe', 'r'], ['pipe', 'w'], ['pipe', 'w']],
$pipes
);

foreach ($pipes as $pipe) {
fclose($pipe);
}

$exitCode = proc_close($process);
// Should be 128 + 9 = 137
var_dump($exitCode);

// Child that exits normally with code 42
$process2 = proc_open(
['/bin/sh', '-c', 'exit 42'],
[['pipe', 'r'], ['pipe', 'w'], ['pipe', 'w']],
$pipes2
);

foreach ($pipes2 as $pipe) {
fclose($pipe);
}

$exitCode2 = proc_close($process2);
// Should be 42
var_dump($exitCode2);

?>
--EXPECT--
int(137)
int(42)
Loading