⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cimserver.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        logsDirectory = configManager->getCurrentValue("logdir");        logsDirectory =         ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));#ifdef PEGASUS_OS_OS400    }  // end if (os400StartupOption == false)#endif        // Set up the Logger. This does not open the logs        // Might be more logical to clean before set.        // ATTN: Need tool to completely disable logging.#if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \!defined(PEGASUS_OS_OS400)        Logger::setHomeDirectory(logsDirectory);#endif        //        // Check to see if we need to shutdown CIMOM         //        if (shutdownOption)        {            String configTimeout =                 configManager->getCurrentValue("shutdownTimeout");            Uint32 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);                        shutdownCIMOM(timeoutValue);#ifdef PEGASUS_OS_OS400        //l10n        //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,            //"CIM Server stopped.");          Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,            "src.Server.cimserver.SERVER_STOPPED",            "CIM Server stopped.");            cimserver_exitRC(0);#else            //l10n            //cout << "CIM Server stopped." << endl;            MessageLoaderParms parms("src.Server.cimserver.SERVER_STOPPED",                                     "CIM Server stopped.");            cout << MessageLoader::getMessage(parms) << endl;            return(0);#endif        }#if defined(PEGASUS_DEBUG)        // Leave this in until people get familiar with the logs.        //l10n        //cout << "Logs Directory = " << logsDirectory << endl;        MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",                                 "Logs Directory = ");        cout << MessageLoader::getMessage(parms) << logsDirectory << endl;#endif    }    catch (UnrecognizedConfigProperty& e)    {#ifdef PEGASUS_OS_OS400    //l10n    //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,            //"Error: $0",e.getMessage());      Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,            "src.Server.cimserver.ERROR",            "Error: $0",e.getMessage()); #else    //l10n    //cout << "Error: " << e.getMessage() << endl;    MessageLoaderParms parms("src.Server.cimserver.ERROR",                             "Error: $0",                             e.getMessage());    cout << MessageLoader::getMessage(parms) << endl;#endif    }    // Bug 2148 - Here is the order of operations for determining the server HTTP and HTTPS ports.    // 1) If the user explicitly specified a port, use it.    // 2) If the user did not specify a port, get the port from the services file.    // 3) If no value is specified in the services file, use the IANA WBEM default port.    // Note that 2 and 3 are done within the System::lookupPort method    // An empty string from the ConfigManager implies that the user did not specify a port.    Uint32 portNumberHttps=0;    Uint32 portNumberHttp=0;    Uint32 portNumberExportHttps=0;    if (enableHttpsConnection)    {        String httpsPort = configManager->getCurrentValue("httpsPort");        if (httpsPort == String::EMPTY)        {            //            // Look up the WBEM-HTTPS port number            //            portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);        } else        {                    //            // user-specified            //            CString portString = httpsPort.getCString();            char* end = 0;            portNumberHttps = strtol(portString, &end, 10);            if(!(end != 0 && *end == '\0'))            {                InvalidPropertyValue e("httpsPort", httpsPort);                cerr << e.getMessage() << endl;                exit(1);            }        }    }    if (enableHttpConnection)    {        String httpPort = configManager->getCurrentValue("httpPort");        if (httpPort == String::EMPTY)        {            //            // Look up the WBEM-HTTP port number            //            portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT);        } else        {            //            // user-specified            //            CString portString = httpPort.getCString();            char* end = 0;            portNumberHttp = strtol(portString, &end, 10);            if(!(end != 0 && *end == '\0'))            {                InvalidPropertyValue e("httpPort", httpPort);                cerr << e.getMessage() << endl;                exit(1);            }        }    }#if defined(PEGASUS_DEBUG)    // Put out startup up message.    cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getVersion() << endl;    //l10n    //cout << "Built " << __DATE__ << " " << __TIME__ << endl;    //cout <<"Starting..."    MessageLoaderParms parms("src.Server.cimserver.STARTUP_MESSAGE",                             "Built $0 $1\nStarting...",                             __DATE__,                             __TIME__);#endif//l10n// reset message loading to NON-process localeMessageLoader::_useProcessLocale = false; //l10n    // Get the parent's PID before forking    _cimServerProcess->set_parent_pid(System::getPID());        // do we need to run as a daemon ?    if (daemonOption)    {        if(-1 == _cimServerProcess->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::CIMSERVER, 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::CIMSERVER, Logger::SEVERE,                             e.getMessage());     }        #ifdef PEGASUS_OS_OS400    // Special server initialization code for OS/400.    if (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::CIMSERVER, 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(_cimServerProcess->isCIMServerRunning())    {    //l10n        //cout << "Unable to start CIMServer." << endl;        //cout << "CIMServer is already running." << endl;        MessageLoaderParms parms("src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",                     "Unable to start CIMServer.\nCIMServer 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)                _cimServerProcess->notify_parent(1);        return(1);    }     #endif    // try loop to bind the address, and run the server    try    {    _monitor  = new Monitor();    //PEP#222    //CIMServer server(&monitor);    //CimserverHolder cimserverHolder( &server );    _cimServer = new CIMServer(_monitor);        if (enableHttpConnection)        {            _cimServer->addAcceptor(false, portNumberHttp, false, false);            //l10n            //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,                        //"Listening on HTTP port $0.", portNumberHttp);                                    Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,                            "src.Server.cimserver.LISTENING_ON_HTTP_PORT",                            "Listening on HTTP port $0.", portNumberHttp);        }        if (enableHttpsConnection)        {            _cimServer->addAcceptor(false, portNumberHttps, true, false);            //l10n            //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,                        //"Listening on HTTPS port $0.", portNumberHttps);            Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,                            "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",                            "Listening on HTTPS port $0.", portNumberHttps);        }#ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET        _cimServer->addAcceptor(true, 0, false, false);        //l10n        //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,                    //"Listening on local connection socket.");        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,              "src.Server.cimserver.LISTENING_ON_LOCAL",              "Listening on local connection socket.");#endif#if defined(PEGASUS_DEBUG)        if (enableHttpConnection)        {            //l10n            //cout << "Listening on HTTP port " << portNumberHttp << endl;      MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTP_PORT",                   "Listening on HTTP port $0.", portNumberHttp);            cout << MessageLoader::getMessage(parms) << endl;        }        if (enableHttpsConnection)        {            //l10n            //cout << "Listening on HTTPS port " << portNumberHttps << endl;            MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTPS_PORT",                     "Listening on HTTPS port $0.", portNumberHttps);            cout << MessageLoader::getMessage(parms) << endl;        }# ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET        //l10n        //cout << "Listening on local connection socket" << endl;        MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_LOCAL",                 "Listening on local connection socket.");        cout << MessageLoader::getMessage(parms) << endl;# endif#endif        // bind throws an exception if the bind fails        try {            _cimServer->bind();	} catch (const BindFailedException &e)	{#ifdef PEGASUS_DEBUG        MessageLoaderParms parms("src.Server.cimserver.BIND_FAILED",                 "Could not bind: $0.", e.getMessage());        cout << MessageLoader::getMessage(parms) << endl;#endif        Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,            "src.Server.cimserver.BIND.FAILED",            "Could not bind:  $0", e.getMessage());	   deleteCIMServer();	   return 1;	}    // 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)        _cimServerProcess->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(_cimServerProcess->getPIDFileName());        // open the file        FILE *pid_file = fopen(_cimServerProcess->getPIDFileName(), "w");        if (pid_file)        {            // save the pid in the file            fprintf(pid_file, "%ld\n", _cimServerProcess->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::CIMSERVER,            Logger::INFORMATION,            "src.Server.cimserver.STARTED_VERSION",            "Started $0 version $1.",            _cimServerProcess->getProductName(), _cimServerProcess->getVersion());        //        // Loop to call CIMServer's runForever() method until CIMServer        // has been shutdown        //    while( !_cimServer->terminated() )    {      _cimServer->runForever();    }        //        // normal termination        //        // Put server shutdown message to the logger        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,            Logger::INFORMATION, "src.Server.cimserver.STOPPED",            "$0 stopped.", _cimServerProcess->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(_cimServerProcess->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::CIMSERVER, 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("src.Server.cimserver.ERROR",                             "Error: $0", e.getMessage());    PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);#endif    //        // notify parent process (if there is a parent process) to terminate        //        if (daemonOption)                _cimServerProcess->notify_parent(1);        deleteCIMServer();        return 1;    }    deleteCIMServer();    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -