GitInfo: Don't try shelling out if it's disabled
[lhc/web/wiklou.git] / includes / ForkController.php
index 655d756..cc16964 100644 (file)
@@ -19,6 +19,7 @@
  *
  * @file
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Class for managing forking command line scripts.
@@ -53,7 +54,7 @@ class ForkController {
        const RESTART_ON_ERROR = 1;
 
        public function __construct( $numProcs, $flags = 0 ) {
-               if ( PHP_SAPI != 'cli' ) {
+               if ( !wfIsCLI() ) {
                        throw new MWException( "ForkController cannot be used from the web." );
                }
                $this->procsToStart = $numProcs;
@@ -133,8 +134,7 @@ class ForkController {
                                $this->termReceived = false;
                        }
                } while ( count( $this->children ) );
-
-               $this->initProcess();
+               pcntl_signal( SIGTERM, SIG_DFL );
                return 'done';
        }
 
@@ -150,12 +150,14 @@ class ForkController {
 
        protected function prepareEnvironment() {
                global $wgMemc;
-               $wgMemc = null; // TODO: change all code that accesses this directly!
-
-               // NOTE: we want to destroy global service instances before forking,
-               // so no external resources such as database connections get copied
-               // to the child processes.
-               \MediaWiki\MediaWikiServices::disableStorageBackend();
+               // Don't share DB, storage, or memcached connections
+               MediaWikiServices::resetChildProcessServices();
+               FileBackendGroup::destroySingleton();
+               LockManagerGroup::destroySingletons();
+               JobQueueGroup::destroySingletons();
+               ObjectCache::clear();
+               RedisConnectionPool::destroySingletons();
+               $wgMemc = null;
        }
 
        /**
@@ -177,7 +179,7 @@ class ForkController {
                        }
 
                        if ( !$pid ) {
-                               $this->initProcess();
+                               $this->initChild();
                                $this->childNumber = $i;
                                return 'child';
                        } else {
@@ -189,10 +191,9 @@ class ForkController {
                return 'parent';
        }
 
-       protected function initProcess() {
-               // Reset services, so we don't re-use connections.
-               \MediaWiki\MediaWikiServices::resetChildProcessServices();
-
+       protected function initChild() {
+               global $wgMemc, $wgMainCacheType;
+               $wgMemc = wfGetCache( $wgMainCacheType );
                $this->children = null;
                pcntl_signal( SIGTERM, SIG_DFL );
        }