php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71804 proc_close does not return exit code
Submitted: 2016-03-11 19:00 UTC Modified: 2016-06-29 18:24 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mark at mpen dot ca Assigned: cmb (profile)
Status: Closed Package: Program Execution
PHP Version: 7.0.4 OS: Ubuntu 14.10
Private report: No CVE-ID: None
 [2016-03-11 19:00 UTC] mark at mpen dot ca
Description:
------------
proc_close always return exit code -1 on PHP 7 when it should be 0 (as it does on PHP 5.6).

$ php7 --version
PHP 7.0.4 (cli) (built: Mar 11 2016 10:54:16) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies


Compiled with:

./configure  --with-openssl --with-layout=GNU --with-pear --enable-ftp --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-session --enable-libxml --enable-xml --with-zlib=yes --enable-mbstring=all --with-gettext --with-pspell --with-gd --enable-gd-native-ttf --with-freetype-dir=/usr/local/lib/ --with-jpeg-dir=/usr/local/lib/ --enable-sockets --enable-pcntl --enable-sigchild --with-mcrypt=/usr/local/lib --enable-posix --enable-dom --enable-simplexml --with-readline --enable-bcmath 


Test script:
---------------
<?php
$proc = proc_open("pwd",[1=>['pipe','w']], $pipes);
var_dump(stream_get_contents($pipes[1]));
fclose($pipes[1]);
var_dump(proc_close($proc));


Expected result:
----------------
Exit code 0

Actual result:
--------------
Exit code -1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-15 04:22 UTC] as@php.net
Having trouble reproducing. Can you attach strace output for 5.6 and 7? Invoke like:

    $ strace -ttt -T -f -s1024 -o strace.log php test.php

Thanks.
 [2016-03-17 16:12 UTC] mark at mpen dot ca
Not sure how to attach files; it wouldn't let me submit them as patches. I've uploaded them to pastebin:

- PHP 5.6 strace: http://pastebin.com/SNuJGAZW
- PHp 7.0.4 strace: http://pastebin.com/akrFjzpT
 [2016-03-20 05:43 UTC] as@php.net
In the PHP 7 trace, I noticed that the parent process is setting a signal handler for SIGCHLD. (Search for "rt_sigaction(SIGCHLD".) Searching backwards from there, I was able to reproduce the bug by recompiling with `--enable-sigchild` (already present in your binary). This switch is from 15+ years ago (commit 674f4bac) and causes PHP to reap all child processes asynchronously:

https://github.com/php/php-src/blob/PHP-7.0.4/main/main.c#L1515-L1523

`proc_close` also attempts to reap the child process here:

https://github.com/php/php-src/blob/PHP-7.0.4/ext/standard/proc_open.c#L228

but at that point it has already been reaped by `sigchld_handler` so `waitpid` returns -1.

The only way I can think of fixing this is to keep track of exit statuses in `sigchld_handler` and check that in `proc_close` if `PHP_SIGCHILD` is defined. Very ugly.

Alternatively we might be able to deprecate `--enable-sigchild`.

For your specific case, you likely do not need `--enable-sigchild`, and recompiling without it should fix your issue.
 [2016-03-21 16:20 UTC] mark at mpen dot ca
Thank you for investigating, disabling sigchild fixed it for me. I don't *think* I need sigchild anymore (I'm not entirely sure what it does), so this should be fine for me, but something should probably be done about this to warn others because it looks like a breaking change.
 [2016-03-21 21:04 UTC] as@php.net
I agree it should at least be documented somewhere.

By the way, this doesn't appear to be a new bug. After investigating I found many bugs reporting the same behavior. Google query: `site:bugs.php.net "proc_close" "--enable-sigchild"`

You should file a bug with the maintainer of the PHP 7 package you used. They should recompile without `--enable-sigchild`.
 [2016-03-22 00:00 UTC] mark at mpen dot ca
Oh really? I thought that was the same configuration we were running on PHP 5.6 according to our internal documentation, but I guess not! Sorry for the dupe. I guess our PHP 5.6 install didn't have it after all.
 [2016-06-29 18:23 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=339529
Log: Fix #71804: proc_close does not return exit code
 [2016-06-29 18:24 UTC] cmb@php.net
-Status: Open +Status: Closed -Type: Bug +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2016-06-29 18:24 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:07 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=1ad5dfe5e0fc836e239d03de25a91336c409cd30
Log: Fix #71804: proc_close does not return exit code
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC