diff --git a/core/mutex.class.inc.php b/core/mutex.class.inc.php index aa3c3bae3..8c7a7a918 100644 --- a/core/mutex.class.inc.php +++ b/core/mutex.class.inc.php @@ -37,8 +37,19 @@ class iTopMutex public function __construct($sName, $sDBHost = null, $sDBUser = null, $sDBPwd = null) { // Compute the name of a lock for mysql - // Note: the name is server-wide!!! + // Note: names are server-wide!!! So let's make the name specific to this iTop instance + $oConfig = utils::GetConfig(); // Will return an empty config when called during the setup + $sDBName = $oConfig->GetDBName(); + $sDBSubname = $oConfig->GetDBSubname(); $this->sName = 'itop.'.$sName; + if (substr($sName, -strlen($sDBName.$sDBSubname)) != $sDBName.$sDBSubname) + { + // If the name supplied already ends with the expected suffix + // don't add it twice, since the setup may try to detect an already + // running cron job by its mutex, without knowing if the config already exists or not + $this->sName .= $sDBName.$sDBSubname; + } + $this->bLocked = false; // Not yet locked if (!array_key_exists($this->sName, self::$aAcquiredLocks)) @@ -48,7 +59,6 @@ class iTopMutex // It is a MUST to create a dedicated session each time a lock is required, because // using GET_LOCK anytime on the same session will RELEASE the current and unique session lock (known issue) - $oConfig = utils::GetConfig(); $sDBHost = is_null($sDBHost) ? $oConfig->GetDBHost() : $sDBHost; $sDBUser = is_null($sDBUser) ? $oConfig->GetDBUser() : $sDBUser; $sDBPwd = is_null($sDBPwd) ? $oConfig->GetDBPwd() : $sDBPwd; diff --git a/setup/wizardsteps.class.inc.php b/setup/wizardsteps.class.inc.php index 3f5515beb..a9fcfba2d 100644 --- a/setup/wizardsteps.class.inc.php +++ b/setup/wizardsteps.class.inc.php @@ -618,7 +618,7 @@ EOF ); $oMutex = new iTopMutex( - 'cron.'.$this->oWizard->GetParameter('db_name', '').'_'.$this->oWizard->GetParameter('db_prefix', ''), + 'cron'.$this->oWizard->GetParameter('db_name', '').$this->oWizard->GetParameter('db_prefix', ''), $this->oWizard->GetParameter('db_server', ''), $this->oWizard->GetParameter('db_user', ''), $this->oWizard->GetParameter('db_pwd', '') diff --git a/synchro/synchro_import.php b/synchro/synchro_import.php index b238a8db7..88817aaba 100644 --- a/synchro/synchro_import.php +++ b/synchro/synchro_import.php @@ -468,7 +468,7 @@ try // Prepare insert columns $sInsertColumns = '`'.implode('`, `', $aInputColumns).'`'; - $oMutex = new iTopMutex('synchro_import_'.$oDataSource->GetKey().'_'.MetaModel::GetConfig()->GetDBName().'_'.MetaModel::GetConfig()->GetDBSubname()); + $oMutex = new iTopMutex('synchro_import_'.$oDataSource->GetKey()); $oMutex->Lock(); foreach($aData as $iRow => $aRow) { diff --git a/synchro/synchrodatasource.class.inc.php b/synchro/synchrodatasource.class.inc.php index 6f66f4bcb..a79e0808a 100644 --- a/synchro/synchrodatasource.class.inc.php +++ b/synchro/synchrodatasource.class.inc.php @@ -2415,7 +2415,7 @@ class SynchroExecution self::$m_oCurrentTask = $this->m_oDataSource; - $oMutex = new iTopMutex('synchro_process_'.$this->m_oDataSource->GetKey().'_'.MetaModel::GetConfig()->GetDBName().'_'.MetaModel::GetConfig()->GetDBSubname()); + $oMutex = new iTopMutex('synchro_process_'.$this->m_oDataSource->GetKey()); try { $oMutex->Lock(); diff --git a/webservices/cron.php b/webservices/cron.php index 43b5b01f5..588f687ba 100644 --- a/webservices/cron.php +++ b/webservices/cron.php @@ -354,7 +354,7 @@ $oP->p("Starting: ".time().' ('.date('Y-m-d H:i:s').')'); try { $oConfig = utils::GetConfig(); - $oMutex = new iTopMutex('cron.'.$oConfig->GetDBName().'_'.$oConfig->GetDBSubname()); + $oMutex = new iTopMutex('cron'); if ($oMutex->TryLock()) { // Note: testing this now in case some of the background processes forces the read-only mode for a while