diff --git a/include/transport/config.h b/include/transport/config.h index d6900d304d29afa1689b551ec1c789b2d614f149..4ff5b8fa079f1470b405ebffa8a072a6031d4f66 100644 --- a/include/transport/config.h +++ b/include/transport/config.h @@ -34,6 +34,7 @@ #define CONFIG_BOOL(PTR, KEY) (*PTR)[KEY].as() #define CONFIG_LIST(PTR, KEY) (*PTR)[KEY].as >() #define CONFIG_VECTOR(PTR, KEY) (*PTR)[KEY].as >() +#define CONFIG_HAS_KEY(PTR, KEY) (*PTR).hasKey(KEY) namespace Transport { @@ -75,6 +76,10 @@ class Config { bool reload(); + bool hasKey(const std::string &key) { + return m_variables.find(key) != m_variables.end(); + } + /// Returns value of variable defined by key. /// For variables in sections you can use "section.variable" key format. diff --git a/spectrum_manager/src/main.cpp b/spectrum_manager/src/main.cpp index d4b8e38367f4b05f1412e9dd971bb0fedc913045..227dc83549ccba3fe7dcba837204fc1c4c9bf551 100644 --- a/spectrum_manager/src/main.cpp +++ b/spectrum_manager/src/main.cpp @@ -151,7 +151,10 @@ static void start_all_instances(ManagerConfig *config) { continue; } - std::vector vhosts = CONFIG_VECTOR(&cfg, "vhosts.vhost"); + + std::vector vhosts; + if (CONFIG_HAS_KEY(&cfg, "vhosts.vhost")) + vhosts = CONFIG_VECTOR(&cfg, "vhosts.vhost"); vhosts.push_back(CONFIG_STRING(&cfg, "service.jid")); BOOST_FOREACH(std::string &vhost, vhosts) { @@ -201,7 +204,9 @@ static void stop_all_instances(ManagerConfig *config) { std::cerr << "Can't load config file " << itr->path().string() << ". Skipping...\n"; } - std::vector vhosts = CONFIG_VECTOR(&cfg, "vhosts.vhost"); + std::vector vhosts; + if (CONFIG_HAS_KEY(&cfg, "vhosts.vhost")) + vhosts = CONFIG_VECTOR(&cfg, "vhosts.vhost"); vhosts.push_back(CONFIG_STRING(&cfg, "service.jid")); BOOST_FOREACH(std::string &vhost, vhosts) {