Esempio n. 1
0
 /**
  * Closes the internal GPG subprocess
  *
  * Closes the internal GPG subprocess. Sets the private class property
  * {@link Crypt_GPG_Engine::$_process} to null.
  *
  * @return void
  *
  * @see Crypt_GPG_Engine::_openSubprocess()
  * @see Crypt_GPG_Engine::$_process
  */
 private function _closeSubprocess()
 {
     // clear PINs from environment if they were set
     $_ENV['PINENTRY_USER_DATA'] = null;
     if (is_resource($this->_process)) {
         $this->_debug('CLOSING GPG SUBPROCESS');
         // close remaining open pipes
         foreach (array_keys($this->_openPipes) as $pipeNumber) {
             $this->_closePipe($pipeNumber);
         }
         $exitCode = proc_close($this->_process);
         if ($exitCode != 0) {
             $this->_debug('=> subprocess returned an unexpected exit code: ' . $exitCode);
         }
         $this->_process = null;
         $this->_pipes = array();
         // close file handles before throwing an exception
         if (is_resource($this->_input)) {
             fclose($this->_input);
         }
         if (is_resource($this->_output)) {
             fclose($this->_output);
         }
         $this->_processHandler->throwException($exitCode);
     }
     $this->_closeAgentLaunchProcess();
     if ($this->_agentInfo !== null) {
         $parts = explode(':', $this->_agentInfo, 3);
         if (!empty($parts[1])) {
             $this->_debug('STOPPING GPG-AGENT DAEMON');
             $process = new Crypt_GPG_ProcessControl($parts[1]);
             // terminate agent daemon
             $process->terminate();
             while ($process->isRunning()) {
                 usleep(10000);
                 // 10 ms
                 $process->terminate();
             }
             $this->_debug('GPG-AGENT DAEMON STOPPED');
         }
         $this->_agentInfo = null;
     }
 }
Esempio n. 2
0
 /**
  * Closes a the internal GPG subprocess
  *
  * Closes the internal GPG subprocess. Sets the private class property
  * {@link Crypt_GPG_Engine::$_process} to null.
  *
  * @return void
  *
  * @see Crypt_GPG_Engine::_openSubprocess()
  * @see Crypt_GPG_Engine::$_process
  */
 private function _closeSubprocess()
 {
     // clear PINs from environment if they were set
     $_ENV['PINENTRY_USER_DATA'] = null;
     if (is_resource($this->_process)) {
         $this->_debug('CLOSING GPG SUBPROCESS');
         // close remaining open pipes
         foreach (array_keys($this->_openPipes) as $pipeNumber) {
             $this->_closePipe($pipeNumber);
         }
         $exitCode = proc_close($this->_process);
         if ($exitCode != 0) {
             $this->_debug('=> subprocess returned an unexpected exit code: ' . $exitCode);
             if ($this->_errorCode === Crypt_GPG::ERROR_NONE) {
                 if ($this->_needPassphrase > 0) {
                     $this->_errorCode = Crypt_GPG::ERROR_MISSING_PASSPHRASE;
                 } else {
                     $this->_errorCode = Crypt_GPG::ERROR_UNKNOWN;
                 }
             }
         }
         $this->_process = null;
         $this->_pipes = array();
     }
     $this->_closeAgentLaunchProcess();
     if ($this->_agentInfo !== null) {
         $this->_debug('STOPPING GPG-AGENT DAEMON');
         $parts = explode(':', $this->_agentInfo, 3);
         $pid = $parts[1];
         $process = new Crypt_GPG_ProcessControl($pid);
         // terminate agent daemon
         $process->terminate();
         while ($process->isRunning()) {
             usleep(10000);
             // 10 ms
             $process->terminate();
         }
         $this->_agentInfo = null;
         $this->_debug('GPG-AGENT DAEMON STOPPED');
     }
 }