Changeset - 2b0783187c64
[Not reviewed]
0 2 0
Jan Kaluza - 9 years ago 2016-02-03 06:09:42
jkaluza@redhat.com
Spectrum manager: Catch boost::lexical_cast exceptions.
2 files changed with 21 insertions and 57 deletions:
0 comments (0 inline, 0 general)
spectrum_manager/src/main.cpp
Show inline comments
 
@@ -20,60 +20,12 @@
 
using namespace Transport;
 

	
 
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;
 
	std::string config_file;
 
	std::vector<std::string> command;
 
	boost::program_options::variables_map vm;
 
@@ -169,20 +121,14 @@ int main(int argc, char **argv)
 
		}
 
		else if (cmd == "restart") {
 
			return restart_instances(&config, jid);
 
		}
 

	
 
		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);
 
	
 
		time_t started = time(NULL);
 
		while(get_response().empty()) {
spectrum_manager/src/methods.cpp
Show inline comments
 
@@ -103,13 +103,22 @@ int getPort(const std::string &portfile) {
 
	std::string port;
 
	f >> port;
 

	
 
	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) {
 
	path p(pidfile);
 
	if (!exists(p) || is_directory(p)) {
 
		return 0;
 
@@ -119,16 +128,25 @@ int isRunning(const std::string &pidfile) {
 
	std::string pid;
 
	f >> pid;
 

	
 
	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) {
 
	int rv = 0;
 
	response = "";
 
	path p(CONFIG_STRING(config, "service.config_directory"));
0 comments (0 inline, 0 general)