From 7ce7abac455827aef85ae5a8f369c25ba5331d4f Mon Sep 17 00:00:00 2001 From: Lukasz Kostyra Date: Mon, 13 Oct 2014 14:02:40 +0200 Subject: [PATCH] Allow SCS to launch without any container [Bug] SCS segfaulted when launching without any containers provided in config. [Cause] Some functions assumed that certain config fields should never be empty [Solution] Additional checks to avoid segfault. [Verification] Build, install, run tests, launch SCS without any predefined containers. Try to switch between containers when less than two containers are present. Change-Id: I58a69d55807f686fb168057dfb1b447707351a46 --- server/containers-manager.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/server/containers-manager.cpp b/server/containers-manager.cpp index d8858ab..c9c7ff8 100644 --- a/server/containers-manager.cpp +++ b/server/containers-manager.cpp @@ -112,7 +112,7 @@ ContainersManager::ContainersManager(const std::string& managerConfigPath): mDet } // check if default container exists, throw ContainerOperationException if not found - if (mContainers.find(mConfig.defaultId) == mContainers.end()) { + if (!mConfig.defaultId.empty() && mContainers.find(mConfig.defaultId) == mContainers.end()) { LOGE("Provided default container ID " << mConfig.defaultId << " is invalid."); throw ContainerOperationException("Provided default container ID " + mConfig.defaultId + " is invalid."); @@ -219,9 +219,11 @@ void ContainersManager::startAll() return c1.second->getPrivilege() < c2.second->getPrivilege(); }); - mConfig.foregroundId = foregroundIterator->second->getId(); - LOGI(mConfig.foregroundId << ": no foreground container configured, setting one with highest priority"); - foregroundIterator->second->goForeground(); + if (foregroundIterator != mContainers.end()) { + mConfig.foregroundId = foregroundIterator->second->getId(); + LOGI(mConfig.foregroundId << ": no foreground container configured, setting one with highest priority"); + foregroundIterator->second->goForeground(); + } } } @@ -269,7 +271,10 @@ void ContainersManager::switchingSequenceMonitorNotify() LOGI("switchingSequenceMonitorNotify() called"); auto nextContainerId = getNextToForegroundContainerId(); - focus(nextContainerId); + + if (!nextContainerId.empty()) { + focus(nextContainerId); + } } -- 2.7.4