Changeset View
Changeset View
Standalone View
Standalone View
src/future/exec/PhutilExecPassthru.php
| Show All 28 Lines | /* -( Executing Passthru Commands )---------------------------------------- */ | ||||
| * | * | ||||
| * @return int Error code returned by the subprocess. | * @return int Error code returned by the subprocess. | ||||
| * | * | ||||
| * @task command | * @task command | ||||
| */ | */ | ||||
| public function execute() { | public function execute() { | ||||
| $command = $this->getCommand(); | $command = $this->getCommand(); | ||||
| $profiler = PhutilServiceProfiler::getInstance(); | |||||
| $call_id = $profiler->beginServiceCall( | |||||
| array( | |||||
| 'type' => 'exec', | |||||
| 'subtype' => 'passthru', | |||||
| 'command' => $command, | |||||
| )); | |||||
| $spec = array(STDIN, STDOUT, STDERR); | $spec = array(STDIN, STDOUT, STDERR); | ||||
| $pipes = array(); | $pipes = array(); | ||||
| $unmasked_command = $command->getUnmaskedString(); | $unmasked_command = $command->getUnmaskedString(); | ||||
| if ($this->hasEnv()) { | if ($this->hasEnv()) { | ||||
| $env = $this->getEnv(); | $env = $this->getEnv(); | ||||
| } else { | } else { | ||||
| Show All 27 Lines | if (!is_resource($proc)) { | ||||
| pht( | pht( | ||||
| 'Failed to passthru %s: %s', | 'Failed to passthru %s: %s', | ||||
| 'proc_open()', | 'proc_open()', | ||||
| $errors)); | $errors)); | ||||
| } | } | ||||
| $err = proc_close($proc); | $err = proc_close($proc); | ||||
| $profiler->endServiceCall( | |||||
| $call_id, | |||||
| array( | |||||
| 'err' => $err, | |||||
| )); | |||||
| return $err; | return $err; | ||||
| } | } | ||||
| /* -( Future )------------------------------------------------------------- */ | /* -( Future )------------------------------------------------------------- */ | ||||
| public function isReady() { | public function isReady() { | ||||
| // This isn't really a future because it executes synchronously and has | // This isn't really a future because it executes synchronously and has | ||||
| // full control of the console. We're just implementing the interfaces to | // full control of the console. We're just implementing the interfaces to | ||||
| // make it easier to share code with ExecFuture. | // make it easier to share code with ExecFuture. | ||||
| if (!$this->hasResult()) { | if (!$this->hasResult()) { | ||||
| $result = $this->execute(); | $result = $this->execute(); | ||||
| $this->setResult($result); | $this->setResult($result); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| protected function getServiceProfilerStartParameters() { | |||||
| return array( | |||||
| 'type' => 'exec', | |||||
| 'subtype' => 'passthru', | |||||
| 'command' => phutil_string_cast($this->getCommand()), | |||||
| ); | |||||
| } | |||||
| protected function getServiceProfilerResultParameters() { | |||||
| if ($this->hasResult()) { | |||||
| $err = $this->getResult(); | |||||
| } else { | |||||
| $err = null; | |||||
| } | |||||
| return array( | |||||
| 'err' => $err, | |||||
| ); | |||||
| } | |||||
| } | } | ||||