📄 cimlistener.cpp
字号:
configManager->lookupValue("sslKeyFilePath", sslKeyFilePath); configManager->lookupValue("sslCertificateFilePath", sslCertificateFilePath); configManager->lookupValue("consumerDir", consumerDir); configManager->lookupValue("consumerConfigDir", consumerConfigDir); enableConsumerUnload = configManager->isTrue("enableConsumerUnload"); configManager->lookupIntegerValue("consumerIdleTimeout", consumerIdleTimeout); configManager->lookupIntegerValue("consumerIdleTimeout", consumerIdleTimeout); configManager->lookupIntegerValue("shutdownTimeout", shutdownTimeout); configManager->lookupValue("traceFilePath", traceFile); configManager->lookupIntegerValue("traceLevel", traceLevel); configManager->lookupValue("traceComponents", traceComponents); } catch (Exception& ex) { MessageLoaderParms parms("src.Server.cimserver.INVALID_CONFIG_OPTION", "Invalid configuration option: $0", ex.getMessage()); cout << MessageLoader::getMessage(parms) << endl; exit(0); }#ifdef PEGASUS_OS_OS400 }#endif //Check listener port validity //ATTN: Do we need this? /*CString portString = listenerPort.getCString(); char* end = 0; Uint32 port = strtol(portString, &end, 10); if(!(end != 0 && *end == '\0')) { PEGASUS_STD(cerr) << "Bad HTTP/HTTPS Port Value" << PEGASUS_STD(endl); exit(1); }*/ //Configure trace options if (traceLevel > 0) { Uint32 traceLevelArg = 0; switch (traceLevel) { case 1: traceLevelArg = Tracer::LEVEL1; break; case 2: traceLevelArg = Tracer::LEVEL2; break; case 3: traceLevelArg = Tracer::LEVEL3; break; case 4: traceLevelArg = Tracer::LEVEL4; break; default: break; } Tracer::setTraceFile((const char*)traceFile.getCString()); Tracer::setTraceComponents(traceComponents); Tracer::setTraceLevel(traceLevelArg); }#if defined(PEGASUS_DEBUG) // Put out startup up message. cout << _cimListenerProcess->getProductName() << " " << _cimListenerProcess->getVersion() << endl; //l10n //cout << "Built " << __DATE__ << " " << __TIME__ << endl; //cout <<"Starting..." MessageLoaderParms parms("DynListener.cimlistener.STARTUP_MESSAGE", "CIM Listener built $0 $1\nCIM Listener starting...", __DATE__, __TIME__);#endif//l10n// reset message loading to NON-process localeMessageLoader::_useProcessLocale = false;//l10n // Get the parent's PID before forking _cimListenerProcess->set_parent_pid(System::getPID()); // do we need to run as a daemon ? if (daemonOption) { if(-1 == _cimListenerProcess->cimserver_fork())#ifndef PEGASUS_OS_OS400 { return(-1); }#else { return(-1); } else { return(0); }#endif }// l10n // Now we are after the fork... // Create a dummy Thread object that can be used to store the // AcceptLanguageList object for CIM requests that are serviced // by this thread (initial thread of server). Need to do this // because this thread is not in a ThreadPool, but is used // to service CIM requests. // The run function for the dummy Thread should never be called, Thread *dummyInitialThread = new Thread(dummyThreadFunc, NULL, false); Thread::setCurrent(dummyInitialThread); AcceptLanguageList default_al; try{ default_al = LanguageParser::getDefaultAcceptLanguages(); Thread::setLanguages(new AcceptLanguageList(default_al)); }catch(InvalidAcceptLanguageHeader& e){ Logger::put_l(Logger::ERROR_LOG, System::CIMLISTENER, Logger::SEVERE, "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE", "Could not convert the system process locale into a valid AcceptLanguage format."); Logger::put(Logger::ERROR_LOG, System::CIMLISTENER, Logger::SEVERE, e.getMessage()); }#ifdef PEGASUS_OS_OS400 // Special server initialization code for OS/400. if (_cimListenerProcess->cimserver_initialize() != 0) { // do some logging here! //l10n //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, //"CIM Server failed to initialize"); Logger::put_l(Logger::ERROR_LOG, System::CIMLISTENER, Logger::SEVERE, "src.Server.cimserver.SERVER_FAILED_TO_INITIALIZE", "CIM Server failed to initialize"); return(-1); }#endif#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \|| defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \|| defined(PEGASUS_OS_SOLARIS) || defined (PEGASUS_OS_VMS) umask(S_IWGRP|S_IWOTH); // // check if CIMServer is already running // if CIMServer is already running, print message and // notify parent process (if there is a parent process) to terminate // if(_cimListenerProcess->isCIMServerRunning()) { //l10n //cout << "Unable to start CIMServer." << endl; //cout << "CIMServer is already running." << endl; MessageLoaderParms parms("DynListener.cimlistener.UNABLE_TO_START_LISTENER_ALREADY_RUNNING", "Unable to start CIM Listener.\nCIM Listener is already running."); PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl); // // notify parent process (if there is a parent process) to terminate // if (daemonOption) _cimListenerProcess->notify_parent(1); return(1); }#endif // try loop to bind the address, and run the server try { //ATTN: Need to handle SSL cases //create DynListener _cimListener = new DynamicListener(listenerPort, consumerDir, consumerConfigDir, enableConsumerUnload, consumerIdleTimeout, shutdownTimeout); _cimListener->start(); Logger::put_l(Logger::STANDARD_LOG, System::CIMLISTENER, Logger::INFORMATION, "src.Server.cimserver.LISTENING_ON_PORT", "Listening on port $0.", listenerPort);#if defined(PEGASUS_DEBUG) //Log startup options printf("Starting CIMListener with the following options\n"); printf("\tlistenerPort %d\n", listenerPort); printf("\thttpsConnection %d\n", httpsConnection); printf("\tsslKeyFilePath %s\n", (const char*)sslKeyFilePath.getCString()); printf("\tsslCertificateFilePath %s\n", (const char*)sslCertificateFilePath.getCString()); printf("\tconsumerDir %s\n", (const char*)consumerDir.getCString()); printf("\tconsumerConfigDir %s\n", (const char*)consumerConfigDir.getCString()); printf("\tenableConsumerUnload %d\n", enableConsumerUnload); printf("\tconsumerIdleTimeout %d\n", consumerIdleTimeout); printf("\tshutdownTimeout %d\n", shutdownTimeout); printf("\ttraceFilePath %s\n", (const char*)traceFile.getCString()); printf("\ttraceLevel %d\n", traceLevel); printf("\ttraceComponents %s\n", (const char*)traceComponents.getCString()); printf("\tMessage home is %s\n", (const char*)msgHome.getCString());#endif // notify parent process (if there is a parent process) to terminate // so user knows that there is cimserver ready to serve CIM requests. if (daemonOption) _cimListenerProcess->notify_parent(0); time_t last = 0;#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) \ || defined(PEGASUS_OS_AIX) || defined(PEGASUS_OS_SOLARIS) \ || defined(PEGASUS_OS_VMS) // // create a file to indicate that the cimserver has started and // save the process id of the cimserver process in the file // // remove the old file if it exists System::removeFile(_cimListenerProcess->getPIDFileName()); // open the file FILE *pid_file = fopen(_cimListenerProcess->getPIDFileName(), "w"); if (pid_file) { // save the pid in the file fprintf(pid_file, "%ld\n", _cimListenerProcess->get_server_pid()); fclose(pid_file); }#endif//#if defined(PEGASUS_DEBUG) cout << "Started. " << endl;//#endif // Put server started message to the logger Logger::put_l(Logger::STANDARD_LOG, System::CIMLISTENER, Logger::INFORMATION, "src.Server.cimserver.STARTED_VERSION", "Started $0 version $1.", _cimListenerProcess->getProductName(), _cimListenerProcess->getVersion());#if defined(PEGASUS_OS_TYPE_UNIX) if (daemonOption && !debugOutputOption) { // Direct standard input, output, and error to /dev/null, // since we are running as a daemon. close(0); open("/dev/null", O_RDONLY); close(1); open("/dev/null", O_RDWR); close(2); open("/dev/null", O_RDWR); }#endif#if !defined(PEGASUS_OS_TYPE_WINDOWS)// if signals are defined, do not use old file creation mechanism#ifndef PEGASUS_HAS_SIGNALS#if defined(PEGASUS_DEBUG) printf("Blocking until shutdown signal\n");#endif while (true) { if (FileSystem::exists(LISTENER_STOP_FILE)) { break; } Threads::sleep(500); }#if defined(PEGASUS_DEBUG) printf("Received signal to shutdown\n");#endif FileSystem::removeFile(LISTENER_STOP_FILE); _cimListener->stop();#else // defined(PEGASUS_HAS_SIGNALS) //Temporary workaround is to use a file, as specified above. //wait until signalled to terminate int sig = _cimListenerProcess->cimserver_wait();#if defined(PEGASUS_DEBUG) printf("Returned from sigwait %d\n", sig);#endif if ((sig == PEGASUS_SIGTERM) || (sig == PEGASUS_SIGHUP)) {#if defined(PEGASUS_DEBUG) printf("Graceful shutdown\n");#endif _cimListener->stop(); }#endif#else //ATTN: Implement cimserver_wait for windows so we don't have to loop here //The listener is stopped in the cimserver_stop method by the service control manager while (true) { if (!_cimListener->isAlive()) { break; } Sleep(500); }#endif#if defined(PEGASUS_DEBUG) PEGASUS_STD(cout) << "Stopped\n";#endif // // normal termination // // Put server shutdown message to the logger Logger::put_l(Logger::STANDARD_LOG, System::CIMLISTENER, Logger::INFORMATION, "src.Server.cimserver.STOPPED", "$0 stopped.", _cimListenerProcess->getProductName());#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \|| defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \|| defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_VMS) // // close the file created at startup time to indicate that the // cimserver has terminated normally. // FileSystem::removeFile(_cimListenerProcess->getPIDFileName());#endif } catch(Exception& e) { //l10n //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING, //"Error: $0", e.getMessage()); Logger::put_l(Logger::STANDARD_LOG, System::CIMLISTENER, Logger::WARNING, "src.Server.cimserver.ERROR", "Error: $0", e.getMessage());#ifndef PEGASUS_OS_OS400 //l10n //PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); MessageLoaderParms parms("DynListener.cimlistener.ERROR", "CIM Listener error: $0"); PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);#endif // // notify parent process (if there is a parent process) to terminate // if (daemonOption) _cimListenerProcess->notify_parent(1); delete _cimListener; _cimListener = 0; return 1; } delete _cimListener; _cimListener = 0;#if defined(PEGASUS_DEBUG) printf("Exiting child process\n");#endif return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -