From bf55d8c7b5b8e018f9206bb621856ba68f2c0a2c Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Mon, 7 Nov 2011 13:10:42 +0100 Subject: [PATCH] Check if vhosts are configured before using them --- include/transport/config.h | 5 +++++ spectrum_manager/src/main.cpp | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/transport/config.h b/include/transport/config.h index d6900d30..4ff5b8fa 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 d4b8e383..227dc835 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) {