diff --git a/spectrum_manager/src/methods.cpp b/spectrum_manager/src/methods.cpp index 208fbc06efe696c443f4a6586f822154e3296964..b510b56527d2b9d210a872f187d9577952fbd507 100644 --- a/spectrum_manager/src/methods.cpp +++ b/spectrum_manager/src/methods.cpp @@ -106,7 +106,16 @@ int getPort(const std::string &portfile) { if (port.empty()) return 0; - return boost::lexical_cast(port); + int iport; + try { + iport = boost::lexical_cast(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(pid), 0) != 0) + int ipid = 0; + try { + ipid = boost::lexical_cast(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(pid); + return ipid; } int start_instances(ManagerConfig *config, const std::string &_jid) {