Fixes for duplicateStderr (I833aeb3a)
authorTim Starling <tstarling@wikimedia.org>
Mon, 21 Oct 2013 04:18:04 +0000 (15:18 +1100)
committerTim Starling <tstarling@wikimedia.org>
Mon, 21 Oct 2013 04:18:04 +0000 (15:18 +1100)
* Separate code from data. $2 in limit.sh is an option list.
* Don't duplicate stderr on linux when limit.sh is not used, unless
  duplicateStderr is specified

Change-Id: I8e6e74810864830c12af627bfbe75e74ba34e3e3

includes/GlobalFunctions.php
includes/limit.sh

index 8241d81..d8e6b36 100644 (file)
@@ -2773,10 +2773,6 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(), $limits = array
        $cmd = $envcmd . $cmd;
 
        if ( php_uname( 's' ) == 'Linux' ) {
-               $stderrDuplication = '';
-               if ( $includeStderr ) {
-                       $stderrDuplication = 'exec 2>&1; ';
-               }
                $time = intval ( isset( $limits['time'] ) ? $limits['time'] : $wgMaxShellTime );
                if ( isset( $limits['walltime'] ) ) {
                        $wallTime = intval( $limits['walltime'] );
@@ -2792,14 +2788,14 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(), $limits = array
                        $cmd = '/bin/bash ' . escapeshellarg( "$IP/includes/limit.sh" ) . ' ' .
                                escapeshellarg( $cmd ) . ' ' .
                                escapeshellarg(
-                                       $stderrDuplication .
+                                       "MW_INCLUDE_STDERR=" . ( $includeStderr ? '1' : '' ) . ';' .
                                        "MW_CPU_LIMIT=$time; " .
                                        'MW_CGROUP=' . escapeshellarg( $wgShellCgroup ) . '; ' .
                                        "MW_MEM_LIMIT=$mem; " .
                                        "MW_FILE_SIZE_LIMIT=$filesize; " .
                                        "MW_WALL_CLOCK_LIMIT=$wallTime"
                                );
-               } else {
+               } elseif ( $includeStderr ) {
                        $cmd .= ' 2>&1';
                }
        } elseif ( $includeStderr ) {
index 6c4690e..2a1545b 100644 (file)
@@ -6,6 +6,7 @@
 # and is available on most Linux systems. If Perl was distributed with
 # BSD::Resource included, we would happily use that instead, but it isn't.
 
+MW_INCLUDE_STDERR=
 MW_CPU_LIMIT=0
 MW_CGROUP=
 MW_MEM_LIMIT=0
@@ -15,6 +16,10 @@ MW_WALL_CLOCK_LIMIT=0
 # Override settings
 eval "$2"
 
+if [ -n "$MW_INCLUDE_STDERR" ]; then
+       exec 2>&1
+fi
+
 if [ "$MW_CPU_LIMIT" -gt 0 ]; then
        ulimit -t "$MW_CPU_LIMIT"
 fi