php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8992 exec($cmd,$ret,$status) always return $status is -1
Submitted: 2001-01-30 02:40 UTC Modified: 2001-02-22 05:17 UTC
From: yasushi_takahashi at tsuken dot co dot jp Assigned:
Status: Closed Package: Program Execution
PHP Version: 4.0.3pl1 OS: Linux 2.2.13-33
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: yasushi_takahashi at tsuken dot co dot jp
New email:
PHP Version: OS:

 

 [2001-01-30 02:40 UTC] yasushi_takahashi at tsuken dot co dot jp
PHP scripts
<?
  $cmd = "ls";
  $ar = array();
  exec($cmd, $ar, $atatus); 
  echo $status;
?>
$status is always -1 (accidential it is 0).

May be PHP's source code file ext/standard/exec.c line 187's  pclose(fp) returns -1.
becose  main/main.c line 598's signal(SIGCHLD,sigchild_handler) destory child prosess status.

mey be fixed it  to  replase  ext/standard/exec.c  follows.
add include
#include <signal.h>
add variable declaration
void (*sig_hadler)();
add "signal handler for SIGCHLD set to SIG_DFL" at top of _Exec()
sig_handler = signal (SIGCHLD, SIG_DFL);
add "signal handler for SIGCHLD back to before" at before every return statments
signal (SIGCHLD, sig_handler); 

This is patch. 
-----------------------------start----------------------
diff -uNr php-4.0.3pl1.orig/ext/standard/exec.c php-4.0.3pl1/ext/standard/exec.c
--- php-4.0.3pl1.orig/ext/standard/exec.c       Wed Sep  6 01:55:32 2000
+++ php-4.0.3pl1/ext/standard/exec.c    Tue Jan 30 16:23:40 2001
@@ -30,6 +30,7 @@
 #if HAVE_SYS_WAIT_H
 #include <sys/wait.h>
 #endif
+#include <signal.h>

 /*
  * If type==0, only last line of output is returned (exec)
@@ -46,11 +47,14 @@
        int t, l, ret, output=1;
        int overflow_limit, lcmd, ldir;
        char *b, *c, *d=NULL;
+       void (*sig_handler)();
        PLS_FETCH();

+       sig_handler = signal (SIGCHLD, SIG_DFL);
        buf = (char*) emalloc(EXEC_INPUT_BUF);
     if (!buf) {
                php_error(E_WARNING, "Unable to emalloc %d bytes for exec buffer", EXEC_INPUT_BUF);
+               signal (SIGCHLD, sig_handler);
                return -1;
     }
        buflen = EXEC_INPUT_BUF;
@@ -65,6 +69,7 @@
                if (strstr(cmd, "..")) {
                        php_error(E_WARNING, "No '..' components allowed in path");
                        efree(buf);
+                       signal (SIGCHLD, sig_handler);
                        return -1;
                }
                d = emalloc(l);
@@ -95,6 +100,7 @@
                        php_error(E_WARNING, "Unable to fork [%s]", d);
                        efree(d);
                        efree(buf);
+                       signal (SIGCHLD, sig_handler);
                        return -1;
                }
        } else { /* not safe_mode */
@@ -106,6 +112,7 @@
                if (!fp) {
                        php_error(E_WARNING, "Unable to fork [%s]", cmd);
                        efree(buf);
+                       signal (SIGCHLD, sig_handler);
                        return -1;
                }
        }
@@ -127,6 +134,7 @@
                                        if ( buf == NULL ) {
                                                php_error(E_WARNING, "Unable to erealloc %d bytes for exec buffer",
                                                                buflen + EXEC_INPUT_BUF);
+                                               signal (SIGCHLD, sig_handler);
                                                return -1;
                                        }
                                        buflen += EXEC_INPUT_BUF;
@@ -190,6 +198,7 @@
                ret = WEXITSTATUS(ret);
        }
 #endif
+       signal (SIGCHLD, sig_handler);

        if (d) efree(d);
        efree(buf);
-----------------------------end----------------------

pclose() function is also used in ext/standard/file.c mail.c ext/imap/php_imap.c.
I do not know this influence.

This is part of my  phpinfo() outputs.
Configure Command
                                              './configure' '--enable-sigchild' '--libdir=/var/tmp/php-root/usr/lib/php4'
                                              '--includedir=/usr/include' '--with-pgsql=shared' '--with-interbase'
                                              '--prefix=/var/tmp/php-root//usr' '--with-apxs=/usr/sbin/apxs'
                                              '--with-config-file-path=/etc/httpd' '--enable-safe-mode'
                                              '--disable-debug' '--with-zlib' '--with-gd' '--with-cpdflib'
                                              '--enable-debugger' '--enable-magic-quotes' '--enable-track-vars'
                                              '--enable-versioning'

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-22 05:17 UTC] stas@php.net
Applied to CVS, thanks.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC