Bug #71804 [Com]: proc_close does not return exit code

From: Date: Sun, 20 Mar 2016 05:43:04 +0000
Subject: Bug #71804 [Com]: proc_close does not return exit code
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199956@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71804&edit=1

 ID:                 71804
 Comment by:         as@php.net
 Reported by:        mark at mpen dot ca
 Summary:            proc_close does not return exit code
 Status:             Open
 Type:               Bug
 Package:            Program Execution
 Operating System:   Ubuntu 14.10
 PHP Version:        7.0.4
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2016-03-17 16:12:46] 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-15 04:22:56] 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-11 19:00:30] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=71804&edit=1


Thread (7 messages)

« previous php.bugs (#199956) next »