#17538 [Com]: proc_close() doesn't return exit value of process

From: Date: Thu, 01 Aug 2002 21:44:15 +0000
Subject: #17538 [Com]: proc_close() doesn't return exit value of process
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-15772@lists.php.net to get a copy of this message
ID: 17538 Comment by: kims@contrail.com.au Reported By: kims@contrail.com.au Status: Feedback Bug Type: Filesystem function related Operating System: Debian GNU/Linux PHP Version: 4.0CVS-2002-05-30 Assigned To: wez New Comment: With the renewed interest in this bug, here's a patch I posted to php-dev some time ago. You need the other code in this patch so as to actually return the *correct* exit value, which I don't think the other patch will neccesarily do (although it won't return -1). ? proc_close_patch Index: ext/standard/exec.c =================================================================== RCS file: /repository/php4/ext/standard/exec.c,v retrieving revision 1.76 diff -u -r1.76 exec.c --- ext/standard/exec.c 23 May 2002 10:17:07 -0000 1.76 +++ ext/standard/exec.c 13 Jun 2002 00:03:21 -0000 @@ -559,23 +559,33 @@ GetExitCodeProcess(child, &wstatus); FG(pclose_ret) = wstatus; #else -# if HAVE_SYS_WAIT +#if HAVE_SYS_WAIT_H int wstatus; pid_t child, wait_pid; child = (pid_t)rsrc->ptr; do { + /* fetch status of child process */ wait_pid = waitpid(child, &wstatus, 0); - } while (wait_pid == -1 && errno = EINTR); + + /* if wait_pid == 1 and errno == EINTR, then waitpid() is just + * alerting of a signal that's been caught - so keep looping + * until wait_pid != -1 (the child process has exited) or + * errno != EINTR (there was a real error, not just a caught + * signal) + */ + } while (wait_pid == -1 && errno == EINTR); - if (wait_pid == -1) - FG(pclose_ret) = -1; - else - FG(pclose_ret) = wstatus; -# else + /* if the child process exited normally, set pclose_ret to the exit + * status of the child process, otherwise set it to -1 (this might + * happen if there's no child process, or it didn't exit normally) + */ + FG(pclose_ret) = wait_pid > 0 && WIFEXITED(wstatus) ? + WEXITSTATUS(wstatus) : -1; +#else FG(pclose_ret) = -1; -# endif +#endif #endif } Previous Comments: ------------------------------------------------------------------------ [2002-08-01 16:26:31] kalowsky@php.net marking as feedback until user tests new snapshot. ------------------------------------------------------------------------ [2002-08-01 15:49:19] jflemer@php.net Patch applied by rasmus. Please try latest CVS (or snapshot after now). ------------------------------------------------------------------------ [2002-08-01 12:09:52] jflemer@php.net By the way, it also seems to make lots of zombies, which is probably related. ------------------------------------------------------------------------ [2002-08-01 11:48:16] jflemer@php.net Do you think this could do it? Index: ext/standard/exec.c =================================================================== RCS file: /repository/php4/ext/standard/exec.c,v retrieving revision 1.77 diff -u -r1.77 exec.c --- ext/standard/exec.c 8 Jul 2002 12:52:22 -0000 1.77 +++ ext/standard/exec.c 1 Aug 2002 15:47:29 -0000 @@ -567,7 +567,7 @@ do { wait_pid = waitpid(child, &wstatus, 0); - } while (wait_pid == -1 && errno = EINTR); + } while (wait_pid == -1 && errno == EINTR); if (wait_pid == -1) FG(pclose_ret) = -1; ------------------------------------------------------------------------ [2002-08-01 11:35:42] jflemer@php.net Also w/ 4.3 SNAP 2002-07-03-1200 on RedHat 7.3. Config ops: --with-apxs --with-mysql=/usr/local/mysql --with-dom --with-xmlrpc --with-zlib-dir=/usr Always seems to return -1. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/17538 -- Edit this bug report at http://bugs.php.net/?id=17538&edit=1

« previous php.bugs (#15772) next »