From: <bni...@us...> - 2006-11-16 18:29:10
|
Revision: 400 http://svn.sourceforge.net/omc/?rev=400&view=rev Author: bnicholes Date: 2006-11-16 10:29:03 -0800 (Thu, 16 Nov 2006) Log Message: ----------- Fix a segfault in start up when the environment can not be initialized. This includes making sure that the client thread is not started if the server thread is not running. Modified Paths: -------------- clp/trunk/src/omcclp.cpp clp/trunk/src/omcclp.h Modified: clp/trunk/src/omcclp.cpp =================================================================== --- clp/trunk/src/omcclp.cpp 2006-11-15 21:38:54 UTC (rev 399) +++ clp/trunk/src/omcclp.cpp 2006-11-16 18:29:03 UTC (rev 400) @@ -142,6 +142,7 @@ Int32 OMCCLPServerThread::run() { int cc; + bool initialized = false; OMCClpdEnvRef env = OMCClpdEnv::instance(); LoggerRef logger(new CerrLogger); NonRecursiveMutexLock localLock(m_guard); @@ -157,51 +158,78 @@ env->init(); m_logger = env->getLogger(OMCClpdEnv::COMPONENT_NAME); - - OW_LOG_DEBUG(m_logger, "clpd Environment initialized"); - - int sig; - env->startServices(); - m_running = true; - OW_LOG_INFO(m_logger, "clpd is now running"); - - m_condition.notifyAll(); - - while(!m_shuttingDown) - { - // runSelectEngine will only return once something has been put into - // the signal pipe or an error has happened - env->runSelectEngine(); - if ((cc = sigPipe->readInt(&sig)) == -1) - { - continue; - } - - OW_LOG_INFO(m_logger, "clp server received shutdown notification." - " Initiating shutdown."); - env->shutdown(); - } + initialized = true; } catch (Exception& e) { - OW_LOG_FATAL_ERROR(m_logger, "* EXCEPTION CAUGHT IN clpd MAIN!"); - OW_LOG_FATAL_ERROR(m_logger, Format("* %1", e)); + cerr << "* EXCEPTION CAUGHT IN clp server startup!" << endl; + cerr << Format("* %1", e) << endl; } catch (std::exception& e) { - OW_LOG_FATAL_ERROR(m_logger, "* std::exception CAUGHT IN clpd MAIN!"); - OW_LOG_FATAL_ERROR(m_logger, Format("* Message: %1", e.what())); + cerr << "* EXCEPTION CAUGHT IN clp server startup!" << endl; + cerr << Format("* Message: %1", e.what()) << endl; } catch (...) { - OW_LOG_FATAL_ERROR(m_logger, "* UNKNOWN EXCEPTION CAUGHT IN clpd MAIN!"); + cerr << "* UNKNOWN EXCEPTION CAUGHT IN clpd MAIN!" << endl; } - m_running = false; - OW_LOG_DEBUG(m_logger, "OMCCLPServer::run waiting on thread barrier"); - m_threadBarrier.wait(); - OW_LOG_DEBUG(m_logger, "Exiting CLP server thread"); + if (initialized) + { + OW_LOG_DEBUG(m_logger, "clpd Environment initialized"); + + try + { + int sig; + env->startServices(); + m_running = true; + OW_LOG_INFO(m_logger, "clpd is now running"); + + m_condition.notifyAll(); + + while(!m_shuttingDown) + { + // runSelectEngine will only return once something has been put into + // the signal pipe or an error has happened + env->runSelectEngine(); + if ((cc = sigPipe->readInt(&sig)) == -1) + { + continue; + } + + OW_LOG_INFO(m_logger, "clp server received shutdown notification." + " Initiating shutdown."); + env->shutdown(); + } + } + catch (Exception& e) + { + OW_LOG_FATAL_ERROR(m_logger, "* EXCEPTION CAUGHT IN clpd MAIN!"); + OW_LOG_FATAL_ERROR(m_logger, Format("* %1", e)); + } + catch (std::exception& e) + { + OW_LOG_FATAL_ERROR(m_logger, "* std::exception CAUGHT IN clpd MAIN!"); + OW_LOG_FATAL_ERROR(m_logger, Format("* Message: %1", e.what())); + } + catch (...) + { + OW_LOG_FATAL_ERROR(m_logger, "* UNKNOWN EXCEPTION CAUGHT IN clpd MAIN!"); + } + m_running = false; + OW_LOG_DEBUG(m_logger, "OMCCLPServer::run waiting on thread barrier"); + m_threadBarrier.wait(); + OW_LOG_DEBUG(m_logger, "Exiting CLP server thread"); + } + else + { + cerr << "Exiting CLP server thread" << endl; + m_condition.notifyAll(); + return -1; + } + return 0; } @@ -330,7 +358,6 @@ { Condition cond; NonRecursiveMutex lock; - OMCCLPClientThread clpt; OMCCLPServerThread clpsvrt(cond, lock); int cc, c; @@ -338,48 +365,94 @@ try { + NonRecursiveMutexLock localLock(lock); + // parse command line, and build the urlList CmdLineParser parser(argc, argv, g_options, CmdLineParser::E_NON_OPTION_ARGS_ALLOWED); - if (parser.isSet(E_CMDOPT_HELP)) { usage(); return 0; } - - if (parser.isSet(E_CMDOPT_URL)) - { - String val = parser.getOptionValue(E_CMDOPT_URL); - clpt.setCIMURL(val); - } - if (parser.isSet(E_CMDOPT_NS)) - { - String val = parser.getOptionValue(E_CMDOPT_NS); - clpt.setCIMNamespace(val); - } if (parser.isSet(E_CMDOPT_CONFIG)) { String val = parser.getOptionValue(E_CMDOPT_CONFIG); - clpt.setConfFilename(val); clpsvrt.setConfFilename(val); } - if (parser.isSet(E_CMDOPT_CMD)) - { - String val = parser.getOptionValue(E_CMDOPT_CMD); - clpt.setExecCmd(val); - } if (parser.isSet(E_CMDOPT_DEBUG)) { clpsvrt.setDebugMode(true); } - clpt.setScriptFilenames(parser.getNonOptionArgs()); + /* Start the server and wait for it to initialize. */ + clpsvrt.start(); + cond.wait(localLock); + localLock.release(); + + if (clpsvrt.running()) + { + OMCCLPClientThread clpt; + + if (parser.isSet(E_CMDOPT_URL)) + { + String val = parser.getOptionValue(E_CMDOPT_URL); + clpt.setCIMURL(val); + } + if (parser.isSet(E_CMDOPT_NS)) + { + String val = parser.getOptionValue(E_CMDOPT_NS); + clpt.setCIMNamespace(val); + } + if (parser.isSet(E_CMDOPT_CONFIG)) + { + String val = parser.getOptionValue(E_CMDOPT_CONFIG); + clpt.setConfFilename(val); + } + if (parser.isSet(E_CMDOPT_CMD)) + { + String val = parser.getOptionValue(E_CMDOPT_CMD); + clpt.setExecCmd(val); + } + clpt.setScriptFilenames(parser.getNonOptionArgs()); + + /* Start the client after the server has completed its startup. */ + clpt.start(); + + setupSigHandler(true); + + SelectTypeArray selArray; + selArray.push_back(sigPipe->getSelectObj()); + sigPipe->setBlocking(UnnamedPipe::E_NONBLOCKING); + + /* This select loop will only return if a signal + has been recieved and the sigpipe has been + written to. */ + do { + Select::select(selArray); + + if ((cc = sigPipe->readInt(&c)) == -1) + { + continue; + } + break; + } while (true); + + /* Call the server and client shutdown to make sure + that everything has been cleaned up. */ + clpt.shutdown(); + clpsvrt.shutdown(); + return 0; + } } catch (CmdLineParserException& e) { printCmdLineParserExceptionMessage(e); usage(); } + catch (AssertionException& a) + { + cerr << "Caught Assertion: " << a << endl; + } catch (CIMException& e) { cerr << "ERROR: CIMException:" << e.getMessage() << endl; @@ -397,52 +470,6 @@ cerr << "ERROR: UnknownException." << endl; } - try - { - NonRecursiveMutexLock localLock(lock); - - /* Start the server and wait for it to initialize. */ - clpsvrt.start(); - cond.wait(localLock); - localLock.release(); - - /* Start the client after the server has completed its startup. */ - clpt.start(); - - setupSigHandler(true); - - SelectTypeArray selArray; - selArray.push_back(sigPipe->getSelectObj()); - sigPipe->setBlocking(UnnamedPipe::E_NONBLOCKING); - - /* This select loop will only return if a signal - has been recieved and the sigpipe has been - written to. */ - do { - Select::select(selArray); - - if ((cc = sigPipe->readInt(&c)) == -1) - { - continue; - } - break; - } while (true); - - /* Call the server and client shutdown to make sure - that everything has been cleaned up. */ - clpt.shutdown(); - clpsvrt.shutdown(); - return 0; - } - catch (AssertionException& a) - { - cerr << "Caught Assertion: " << a << endl; - } - catch (Exception& e) - { - cerr << e << endl; - } - return 1; } Modified: clp/trunk/src/omcclp.h =================================================================== --- clp/trunk/src/omcclp.h 2006-11-15 21:38:54 UTC (rev 399) +++ clp/trunk/src/omcclp.h 2006-11-16 18:29:03 UTC (rev 400) @@ -79,6 +79,7 @@ virtual void shutdown(); virtual Int32 run (); + bool running() {return m_running;} void setDebugMode(bool debug) {m_debugMode = debug;} void setConfFilename (const String filename) {m_data_filename = filename;} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |