Fixing segmentation fault if container is started without configuration file.
authorMarkus Jung <markus.jung@samsung.com>
Mon, 27 Jul 2015 03:43:30 +0000 (12:43 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Mon, 27 Jul 2015 05:27:45 +0000 (05:27 +0000)
https://jira.iotivity.org/browse/IOT-633

Change-Id: I3559719cf084e462260da55d0b54d0848767e09c
Signed-off-by: Markus Jung <markus.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1926
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
service/resource-encapsulation/src/resourceContainer/src/ResourceContainerImpl.cpp
service/resource-encapsulation/src/resourceContainer/unittests/ResourceContainerTest.cpp

index e3e3d54b8fe93ac49e1cabcf53e84f280a55f619..f9b504d0985345ed4964664b849eb03a60f6f48b 100644 (file)
@@ -88,37 +88,42 @@ namespace OIC
             info_logger() << "Resource container without Java support" << endl;
 #endif
 
-            m_config = new Configuration(configFile);
+            if(!configFile.empty()){
+                m_config = new Configuration(configFile);
 
-            if (m_config->isLoaded())
-            {
-                configInfo bundles;
-                m_config->getConfiguredBundles(&bundles);
-
-                for (unsigned int i = 0; i < bundles.size(); i++)
+                if (m_config->isLoaded())
                 {
-                    RCSBundleInfo *bundleInfo = RCSBundleInfo::build();
-                    bundleInfo->setPath(bundles[i]["path"]);
-                    bundleInfo->setVersion(bundles[i]["version"]);
-                    bundleInfo->setID(bundles[i]["id"]);
-                    if (!bundles[i]["activator"].empty())
-                    {
-                        string activatorName = bundles[i]["activator"];
-                        std::replace(activatorName.begin(), activatorName.end(), '.', '/');
-                        ((BundleInfoInternal *) bundleInfo)->setActivatorName(activatorName);
-                        ((BundleInfoInternal *) bundleInfo)->setLibraryPath(
-                            bundles[i]["libraryPath"]);
+                    configInfo bundles;
+                    m_config->getConfiguredBundles(&bundles);
 
+                    for (unsigned int i = 0; i < bundles.size(); i++)
+                    {
+                        RCSBundleInfo *bundleInfo = RCSBundleInfo::build();
+                        bundleInfo->setPath(bundles[i]["path"]);
+                        bundleInfo->setVersion(bundles[i]["version"]);
+                        bundleInfo->setID(bundles[i]["id"]);
+                        if (!bundles[i]["activator"].empty())
+                        {
+                            string activatorName = bundles[i]["activator"];
+                            std::replace(activatorName.begin(), activatorName.end(), '.', '/');
+                            ((BundleInfoInternal *) bundleInfo)->setActivatorName(activatorName);
+                            ((BundleInfoInternal *) bundleInfo)->setLibraryPath(
+                                bundles[i]["libraryPath"]);
+
+                        }
+                        info_logger() << "Init Bundle:" << bundles[i]["id"] << ";" << bundles[i]["path"]
+                                      << endl;
+                        registerBundle(bundleInfo);
+                        activateBundle(bundleInfo);
                     }
-                    info_logger() << "Init Bundle:" << bundles[i]["id"] << ";" << bundles[i]["path"]
-                                  << endl;
-                    registerBundle(bundleInfo);
-                    activateBundle(bundleInfo);
+                }
+                else
+                {
+                    error_logger() << "Container started with invalid configfile path" << endl;
                 }
             }
-            else
-            {
-                error_logger() << "Container started with invalid configfile path" << endl;
+            else{
+                info_logger() << "No configuration file for the container provided" << endl;
             }
         }
 
index 54ca6b229ded71f4d642d79104188ac1acfeff1d..148bda72c11eb105c9f699896c501857ddf97184 100644 (file)
@@ -118,7 +118,14 @@ TEST_F(ResourceContainerTest, BundleActivatedWhenContainerStartedWithValidConfig
 
 TEST_F(ResourceContainerTest, BundleNotRegisteredWhenContainerStartedWithInvalidConfigFile)
 {
-    m_pResourceContainer->startContainer("invalideConfig");
+    m_pResourceContainer->startContainer("invalidConfig");
+
+    EXPECT_EQ((unsigned int) 0, m_pResourceContainer->listBundles().size());
+}
+
+TEST_F(ResourceContainerTest, BundleNotRegisteredWhenContainerStartedWithEmptyConfigFile)
+{
+    m_pResourceContainer->startContainer("");
 
     EXPECT_EQ((unsigned int) 0, m_pResourceContainer->listBundles().size());
 }