Spectrum manager: Catch boost::lexical_cast exceptions.
This commit is contained in:
parent
3e074dc557
commit
2b0783187c
2 changed files with 21 additions and 57 deletions
|
@ -23,54 +23,6 @@ using namespace boost::filesystem;
|
|||
|
||||
using namespace boost;
|
||||
|
||||
|
||||
// static void ask_local_servers(ManagerConfig *config, Swift::BoostNetworkFactories &networkFactories, const std::string &message) {
|
||||
// path p(CONFIG_STRING(config, "service.config_directory"));
|
||||
//
|
||||
// try {
|
||||
// if (!exists(p)) {
|
||||
// std::cerr << "Config directory " << CONFIG_STRING(config, "service.config_directory") << " does not exist\n";
|
||||
// exit(6);
|
||||
// }
|
||||
//
|
||||
// if (!is_directory(p)) {
|
||||
// std::cerr << "Config directory " << CONFIG_STRING(config, "service.config_directory") << " does not exist\n";
|
||||
// exit(7);
|
||||
// }
|
||||
//
|
||||
// directory_iterator end_itr;
|
||||
// for (directory_iterator itr(p); itr != end_itr; ++itr) {
|
||||
// if (is_regular(itr->path()) && extension(itr->path()) == ".cfg") {
|
||||
// Config cfg;
|
||||
// if (cfg.load(itr->path().string()) == false) {
|
||||
// std::cerr << "Can't load config file " << itr->path().string() << ". Skipping...\n";
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// if (CONFIG_VECTOR(&cfg, "service.admin_jid").empty() || CONFIG_STRING(&cfg, "service.admin_password").empty()) {
|
||||
// std::cerr << itr->path().string() << ": service.admin_jid or service.admin_password empty. This server can't be queried over XMPP.\n";
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// finished++;
|
||||
// Swift::Client *client = new Swift::Client(CONFIG_VECTOR(&cfg, "service.admin_jid")[0], CONFIG_STRING(&cfg, "service.admin_password"), &networkFactories);
|
||||
// client->setAlwaysTrustCertificates();
|
||||
// client->onConnected.connect(boost::bind(&handleConnected, client, CONFIG_STRING(&cfg, "service.jid")));
|
||||
// client->onDisconnected.connect(bind(&handleDisconnected, client, _1, CONFIG_STRING(&cfg, "service.jid")));
|
||||
// client->onMessageReceived.connect(bind(&handleMessageReceived, client, _1, CONFIG_STRING(&cfg, "service.jid")));
|
||||
// Swift::ClientOptions opt;
|
||||
// opt.allowPLAINWithoutTLS = true;
|
||||
// client->connect(opt);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch (const filesystem_error& ex) {
|
||||
// std::cerr << "boost filesystem error\n";
|
||||
// exit(5);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
ManagerConfig config;
|
||||
|
@ -172,14 +124,8 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
ask_local_server(&config, networkFactories, jid, cmd);
|
||||
// std::string message = command;
|
||||
// m = &message;
|
||||
|
||||
// ask_local_server(&config, networkFactories, message);
|
||||
|
||||
eventLoop.runUntilEvents();
|
||||
|
||||
|
||||
struct timeval td_start,td_end;
|
||||
float elapsed = 0;
|
||||
gettimeofday(&td_start, NULL);
|
||||
|
|
|
@ -106,7 +106,16 @@ int getPort(const std::string &portfile) {
|
|||
if (port.empty())
|
||||
return 0;
|
||||
|
||||
return boost::lexical_cast<int>(port);
|
||||
int iport;
|
||||
try {
|
||||
iport = boost::lexical_cast<int>(port);
|
||||
}
|
||||
catch (const boost::bad_lexical_cast &e) {
|
||||
std::cout << "Error: Error converting port \"" << port << "\" to integer.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
return iport;
|
||||
}
|
||||
|
||||
int isRunning(const std::string &pidfile) {
|
||||
|
@ -122,10 +131,19 @@ int isRunning(const std::string &pidfile) {
|
|||
if (pid.empty())
|
||||
return 0;
|
||||
|
||||
if (kill(boost::lexical_cast<int>(pid), 0) != 0)
|
||||
int ipid = 0;
|
||||
try {
|
||||
ipid = boost::lexical_cast<int>(pid);
|
||||
}
|
||||
catch (const boost::bad_lexical_cast &e) {
|
||||
std::cout << "Error: Error converting pid \"" << pid << "\" to integer.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (kill(ipid, 0) != 0)
|
||||
return 0;
|
||||
|
||||
return boost::lexical_cast<int>(pid);
|
||||
return ipid;
|
||||
}
|
||||
|
||||
int start_instances(ManagerConfig *config, const std::string &_jid) {
|
||||
|
|
Loading…
Add table
Reference in a new issue