📄 cimlistener.cpp
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Notes on deamon operation (Unix) and service operation (Win 32)://// To run pegasus listener as a daemon on Unix platforms://// cimlistener//// To NOT run pegasus listener as a daemon on Unix platforms://// cimlistener --nodaemon//// The daemon setting has no effect on windows operation.//// To shutdown pegasus listener, use the -s option://// cimlistener -s//// To run pegasus listener as an NT service, there are FOUR different possibilities://// To INSTALL the Pegasus service,//// cimlistener -install//// To REMOVE the Pegasus service,//// cimlistener -remove//// To START the Pegasus service,//// net start cimlistener// or// cimlistener -start//// To STOP the Pegasus service,//// net stop cimlistener// or// cimlistener -stop//// Alternatively, you can use the windows service manager. Pegasus listener shows up// in the service database as "Pegasus CIM Listener"//// Mike Day, mdday@us.ibm.com////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/PegasusAssert.h>#include <cstdlib>#include <Pegasus/Common/FileSystem.h>#include <Pegasus/Common/Logger.h>#include <Pegasus/Common/System.h>#include <Pegasus/Common/Tracer.h>#include <Pegasus/Common/Thread.h>#include <Pegasus/Common/LanguageParser.h>#include <Pegasus/Common/PegasusVersion.h>#include <Pegasus/Common/Signal.h>#include <Pegasus/DynListener/DynamicListener.h>#include <Pegasus/DynListener/DynamicListenerConfig.h>#include <Service/ServerProcess.h>#if defined(PEGASUS_OS_TYPE_UNIX)# if defined(PEGASUS_OS_OS400)# include <unistd.cleinc># else# include <unistd.h># endif# include <sys/types.h># include <sys/stat.h># include <fcntl.h>#endifPEGASUS_USING_PEGASUS;PEGASUS_USING_STD;#define PEGASUS_LISTENER_PROCESS_NAME "cimlistener";//Windows service variables are not defined elsewhere in the product//enable ability to override these#ifndef PEGASUS_LISTENER_PRODUCT_NAME#define PEGASUS_LISTENER_PRODUCT_NAME "CIM Listener"#endif#ifndef PEGASUS_LISTENER_SERVICE_NAME#define PEGASUS_LISTENER_SERVICE_NAME "Pegasus CIM Listener"#endif#ifndef PEGASUS_LISTENER_SERVICE_DESCRIPTION#define PEGASUS_LISTENER_SERVICE_DESCRIPTION "Pegasus CIM Listener Service"#endif//The start file is created as soon the child forks and notifies the parent.//This file is used to detect whether the cimserver is running and thus,//it must exist until right before the child process exits.#ifndef LISTENER_START_FILE#define LISTENER_START_FILE "/tmp/cimlistener_start.conf"#endif//The stop file is created to signal the cimserver to shutdown.//We cannot use the earlier file and delete it to "signal shutdown"//because then another cimserver process could be started while we//were still shutting down. This is a workaround for the fact that//signals are not implemented on all platforms. Theoretically,//we should be blocking until the calling process signalled the child//to shutdown.#ifndef LISTENER_STOP_FILE#define LISTENER_STOP_FILE "/tmp/cimlistener_stop.conf"#endifclass CIMListenerProcess : public ServerProcess{public: CIMListenerProcess(void) { cimserver_set_process(this); } virtual ~CIMListenerProcess(void) { } virtual const char* getProductName() const { return PEGASUS_LISTENER_PRODUCT_NAME; } virtual const char* getExtendedName() const { return PEGASUS_LISTENER_SERVICE_NAME; } virtual const char* getDescription() const { return PEGASUS_LISTENER_SERVICE_DESCRIPTION; } //defined in PegasusVersion.h virtual const char* getVersion() const { return PEGASUS_PRODUCT_VERSION; } virtual const char* getProcessName() const { return PEGASUS_LISTENER_PROCESS_NAME; } virtual const char* getPIDFileName() const { return LISTENER_START_FILE; } int cimserver_run( int argc, char** argv, Boolean shutdownOption, Boolean debugOutputOption); void cimserver_stop(void);};AutoPtr<CIMListenerProcess> _cimListenerProcess(new CIMListenerProcess());AutoPtr<DynamicListenerConfig> configManager(DynamicListenerConfig::getInstance());static DynamicListener* _cimListener = 0;//// The command name.//static const char COMMAND_NAME [] = "cimlistener";//// The constant defining usage string.//static const char USAGE [] = "Usage: ";/**Constants representing the command line options.*/static const char OPTION_VERSION = 'v';static const char OPTION_HELP = 'h';static const char OPTION_HOME = 'D';static const char OPTION_SHUTDOWN = 's';static const char OPTION_NO_DAEMON [] = "--nodaemon";static const char LONG_HELP [] = "help";static const char LONG_VERSION [] = "version";static const char OPTION_DEBUGOUTPUT = 'X';static const String PROPERTY_TIMEOUT = "shutdownTimeout";static const String DEFAULT_CONFIG_FILE = "cimlistener.conf";/* PrintHelp - This is temporary until we expand the options manager to allow options help to be defined with the OptionRow entries and presented from those entries.*/void PrintHelp(const char* arg0){ String usage = String (USAGE); usage.append (COMMAND_NAME); usage.append (" [ [ options ] ]\n"); usage.append (" options\n"); usage.append (" -v, --version - displays CIM Listener version number\n"); usage.append (" -h, --help - prints this help message\n"); usage.append (" -s - shuts down CIM Listener\n"); usage.append (" -D [home] - sets pegasus home directory\n");#if defined(PEGASUS_OS_TYPE_WINDOWS) usage.append (" -install [name] - installs pegasus as a Windows Service\n"); usage.append (" [name] is optional and overrides the\n"); usage.append (" default CIM Listener Service Name\n"); usage.append (" -remove [name] - removes pegasus as a Windows Service\n"); usage.append (" [name] is optional and overrides the\n"); usage.append (" default CIM Listener Service Name\n"); usage.append (" -start [name] - starts pegasus as a Windows Service\n"); usage.append (" [name] is optional and overrides the\n"); usage.append (" default CIM Listener Service Name\n"); usage.append (" -stop [name] - stops pegasus as a Windows Service\n"); usage.append (" [name] is optional and overrides the\n"); usage.append (" default CIM Listener Service Name\n\n");#endif#if !defined(PEGASUS_OS_TYPE_WINDOWS) usage.append (" --nodaemon - do NOT run as a daemon\n");#endif cout << endl; cout << _cimListenerProcess->getProductName() << " " << _cimListenerProcess->getVersion() << endl; cout << endl;//ATTN: Add menu items to Server bundle for listener/*#if defined(PEGASUS_OS_TYPE_WINDOWS) MessageLoaderParms parms("src.Server.cimserver.MENU.WINDOWS", usage);#elif defined(PEGASUS_OS_USE_RELEASE_DIRS) MessageLoaderParms parms("src.Server.cimserver.MENU.HPUXLINUXIA64GNU", usage);#else MessageLoaderParms parms("src.Server.cimserver.MENU.STANDARD", usage);#endif cout << MessageLoader::getMessage(parms) << endl;*/ cout << usage;}// l10n//// Dummy function for the Thread object associated with the initial thread.// Since the initial thread is used to process CIM requests, this is// needed to localize the exceptions thrown during CIM request processing.// Note: This function should never be called!//ThreadReturnType PEGASUS_THREAD_CDECL dummyThreadFunc(void *parm){ return((ThreadReturnType)0);}/////////////////////////////////////////////////////////////////////////// MAIN//////////////////////////////////////////////////////////////////////////int main(int argc, char** argv){ String pegasusHome = String::EMPTY; Boolean shutdownOption = false; Boolean debugOutputOption = false;//l10n// Set Message loading to process localeMessageLoader::_useProcessLocale = true;//l10n//l10n#if defined(PEGASUS_OS_AIX) && defined(PEGASUS_HAS_MESSAGES)setlocale(LC_ALL, "");#endif#ifdef PEGASUS_OS_OS400 VFYPTRS_INCDCL; // VFYPTRS local variables // verify pointers #pragma exception_handler (qsyvp_excp_hndlr,qsyvp_excp_comm_area,\ 0,_C2_MH_ESCAPE) for( int arg_index = 1; arg_index < argc; arg_index++ ){ VFYPTRS(VERIFY_SPP_NULL(argv[arg_index])); } #pragma disable_handler // Convert the args to ASCII for(Uint32 i = 0;i< argc;++i) { EtoA(argv[i]); } // Initialize Pegasus home to the shipped OS/400 directory. pegasusHome = OS400_DEFAULT_PEGASUS_HOME;#endif#ifndef PEGASUS_OS_TYPE_WINDOWS // // Get environment variables: //#ifdef PEGASUS_OS_OS400#pragma convert(37) const char* tmp = getenv("PEGASUS_HOME");#pragma convert(0) char home[256] = {0}; if (tmp && strlen(tmp) < 256) { strcpy(home, tmp); EtoA(home); pegasusHome = home; }#else #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS) pegasusHome = AIX_RELEASE_PEGASUS_HOME; #elif !defined(PEGASUS_USE_RELEASE_DIRS) const char* tmp = getenv("PEGASUS_HOME"); if (tmp) { pegasusHome = tmp; } #endif#endif FileSystem::translateSlashes(pegasusHome);#else // windows only char exeDir[MAX_PATH]; HMODULE hExe = GetModuleHandle(NULL); GetModuleFileName(hExe, exeDir, sizeof(exeDir));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -