jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/384929 )

Change subject: Shell\Command: Move code that builds final shell command into 
separate method
......................................................................


Shell\Command: Move code that builds final shell command into separate method

Change-Id: I6aae209fd0b20057b5f7f7129db92c184ec945f8
---
M includes/shell/Command.php
1 file changed, 35 insertions(+), 22 deletions(-)

Approvals:
  MaxSem: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/shell/Command.php b/includes/shell/Command.php
index bd44ef8..1816c5a 100644
--- a/includes/shell/Command.php
+++ b/includes/shell/Command.php
@@ -198,19 +198,12 @@
        }
 
        /**
-        * Executes command. Afterwards, getExitCode() and getOutput() can be 
used to access execution
-        * results.
+        * String together all the options and build the final command
+        * to execute
         *
-        * @return Result
-        * @throws Exception
-        * @throws ProcOpenError
-        * @throws ShellDisabledError
+        * @return array [ command, whether to use log pipe ]
         */
-       public function execute() {
-               $this->everExecuted = true;
-
-               $profileMethod = $this->method ?: wfGetCaller();
-
+       protected function buildFinalCommand() {
                $envcmd = '';
                foreach ( $this->env as $k => $v ) {
                        if ( wfIsWindows() ) {
@@ -229,9 +222,9 @@
                        }
                }
 
+               $useLogPipe = false;
                $cmd = $envcmd . trim( $this->command );
 
-               $useLogPipe = false;
                if ( is_executable( '/bin/bash' ) ) {
                        $time = intval( $this->limits['time'] );
                        $wallTime = intval( $this->limits['walltime'] );
@@ -240,22 +233,42 @@
 
                        if ( $time > 0 || $mem > 0 || $filesize > 0 || 
$wallTime > 0 ) {
                                $cmd = '/bin/bash ' . escapeshellarg( __DIR__ . 
'/limit.sh' ) . ' ' .
-                                          escapeshellarg( $cmd ) . ' ' .
-                                          escapeshellarg(
-                                                  "MW_INCLUDE_STDERR=" . ( 
$this->useStderr ? '1' : '' ) . ';' .
-                                                  "MW_CPU_LIMIT=$time; " .
-                                                  'MW_CGROUP=' . 
escapeshellarg( $this->cgroup ) . '; ' .
-                                                  "MW_MEM_LIMIT=$mem; " .
-                                                  
"MW_FILE_SIZE_LIMIT=$filesize; " .
-                                                  
"MW_WALL_CLOCK_LIMIT=$wallTime; " .
-                                                  "MW_USE_LOG_PIPE=yes"
-                                          );
+                                       escapeshellarg( $cmd ) . ' ' .
+                                       escapeshellarg(
+                                               "MW_INCLUDE_STDERR=" . ( 
$this->useStderr ? '1' : '' ) . ';' .
+                                               "MW_CPU_LIMIT=$time; " .
+                                               'MW_CGROUP=' . escapeshellarg( 
$this->cgroup ) . '; ' .
+                                               "MW_MEM_LIMIT=$mem; " .
+                                               "MW_FILE_SIZE_LIMIT=$filesize; 
" .
+                                               "MW_WALL_CLOCK_LIMIT=$wallTime; 
" .
+                                               "MW_USE_LOG_PIPE=yes"
+                                       );
                                $useLogPipe = true;
                        }
                }
                if ( !$useLogPipe && $this->useStderr ) {
                        $cmd .= ' 2>&1';
                }
+
+               return [ $cmd, $useLogPipe ];
+       }
+
+       /**
+        * Executes command. Afterwards, getExitCode() and getOutput() can be 
used to access execution
+        * results.
+        *
+        * @return Result
+        * @throws Exception
+        * @throws ProcOpenError
+        * @throws ShellDisabledError
+        */
+       public function execute() {
+               $this->everExecuted = true;
+
+               $profileMethod = $this->method ?: wfGetCaller();
+
+               list( $cmd, $useLogPipe ) = $this->buildFinalCommand();
+
                $this->logger->debug( __METHOD__ . ": $cmd" );
 
                // Don't try to execute commands that exceed Linux's 
MAX_ARG_STRLEN.

-- 
To view, visit https://gerrit.wikimedia.org/r/384929
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6aae209fd0b20057b5f7f7129db92c184ec945f8
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: MaxSem <maxsem.w...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to