diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index 55f4dd484958..d0f40db0f78a 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -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 diff --git a/ext/standard/tests/general_functions/proc_close_signal_exit_code.phpt b/ext/standard/tests/general_functions/proc_close_signal_exit_code.phpt new file mode 100644 index 000000000000..ad1765150c15 --- /dev/null +++ b/ext/standard/tests/general_functions/proc_close_signal_exit_code.phpt @@ -0,0 +1,44 @@ +--TEST-- +proc_close() returns 128+signal when child is killed by a signal +--SKIPIF-- + +--FILE-- + +--EXPECT-- +int(137) +int(42)