version 1.1, 2002/11/19 21:32:49
|
version 1.4, 2003/10/22 14:26:19
|
|
|
//%///////////////////////////////////////////////////////////////////////////// |
//%2003//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development |
// The Open Group, Tivoli Systems |
// 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. |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
// | // |
// Modified By: Mary Hinton (m.hinton@verizon.net) | // Modified By: Mary Hinton (m.hinton@verizon.net) |
// Sushma Fernandes (sushma_fernandes@hp.com) | // Sushma Fernandes (sushma_fernandes@hp.com) |
|
// Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com) |
|
// Tony Fiorentino (fiorentino_tony@emc.com) |
|
// Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) |
|
// Jair Santos, Hewlett-Packard Company (jair.santos@hp.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
#include <tchar.h> | #include <tchar.h> |
#include <direct.h> | #include <direct.h> |
| |
|
#include "service.cpp" |
| |
PEGASUS_USING_PEGASUS; | PEGASUS_USING_PEGASUS; |
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
static DWORD dieNow = 0; |
//------------------------------------------------------------------------- |
String *runPath; |
// DEFINES |
|
//------------------------------------------------------------------------- |
|
#define PEGASUS_SERVICE_NAME "wmiserver" |
|
#define PEGASUS_DISPLAY_NAME "Pegasus WMI Mapper" |
|
#define PEGASUS_DESCRIPTION "Pegasus WBEM to WMI Mapper Manager Service" |
|
|
|
//------------------------------------------------------------------------- |
|
// GLOBALS |
|
//------------------------------------------------------------------------- |
CIMServer *server_windows; | CIMServer *server_windows; |
static SERVICE_STATUS pegasus_status; |
static Service pegasus_service(PEGASUS_SERVICE_NAME); |
static SERVICE_STATUS_HANDLE pegasus_status_handle; |
static HANDLE pegasus_service_event; |
|
static LPCSTR g_cimservice_key = TEXT("SYSTEM\\CurrentControlSet\\Services\\%s"); |
VOID WINAPI cimserver_windows_main(int argc, char **argv) ; |
static LPCSTR g_cimservice_home = TEXT("home"); |
VOID WINAPI cimserver_service_start(DWORD, LPTSTR *); |
|
VOID WINAPI cimserver_service_ctrl_handler(DWORD ); |
//------------------------------------------------------------------------- |
DWORD cimserver_initialization(DWORD, LPTSTR *, DWORD *) ; |
// PROTOTYPES |
|
//------------------------------------------------------------------------- |
void GetOptions( |
int cimserver_windows_main(int flag, int argc, char **argv); |
ConfigManager* cm, |
extern void GetOptions(ConfigManager *cm, |
int& argc, | int& argc, |
char** argv, | char** argv, |
const String& pegasusHome); | const String& pegasusHome); |
|
static bool _getRegInfo(const char *lpchKeyword, char *lpchRetValue); |
void cim_server_service(int argc, char **argv ) { cimserver_windows_main(argc, argv); exit(0); } |
static bool _setRegInfo(const char *lpchKeyword, const char *lpchValue); |
int cimserver_fork( ) { return(0); } |
void setHome(String & home); |
int cimserver_kill( ) { return(0); } |
|
Boolean isCIMServerRunning( ) { return(false); } |
//------------------------------------------------------------------------- |
|
// NO-OPs for windows platform |
|
//------------------------------------------------------------------------- |
|
int cimserver_fork(void) { return(0); } |
|
int cimserver_kill(void) { return(0); } |
|
void notify_parent(int id) { return; } |
|
|
|
//------------------------------------------------------------------------- |
|
// START MONITOR Asynchronously |
|
//------------------------------------------------------------------------- |
static void __cdecl cimserver_windows_thread(void *parm) | static void __cdecl cimserver_windows_thread(void *parm) |
{ | { |
| |
|
|
// removes corresponding options and their arguments fromt he command | // removes corresponding options and their arguments fromt he command |
// line. | // line. |
| |
|
String pegasusHome; |
|
|
|
// Windows way to set home |
|
setHome(pegasusHome); |
|
|
|
ConfigManager::setPegasusHome(pegasusHome); |
|
|
ConfigManager* configManager = ConfigManager::getInstance(); | ConfigManager* configManager = ConfigManager::getInstance(); |
int dummy = 0; | int dummy = 0; |
String pegasusHome; |
|
| |
try | try |
{ | { |
|
|
exit(1); | exit(1); |
} | } |
| |
// |
Boolean enableHttpConnection = String::equal( |
// Check the trace options and set global variable |
configManager->getCurrentValue("enableHttpConnection"), "true"); |
// |
Boolean enableHttpsConnection = String::equal( |
Boolean pegasusIOTrace = false; |
configManager->getCurrentValue("enableHttpsConnection"), "true"); |
|
|
if (String::equal(configManager->getCurrentValue("trace"), "true")) |
if (!enableHttpConnection && !enableHttpsConnection) |
{ |
{ |
pegasusIOTrace = true; |
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, |
|
"Neither HTTP nor HTTPS connection is enabled. " |
|
"CIMServer will not be started."); |
|
cerr << "Neither HTTP nor HTTPS connection is enabled. " |
|
"CIMServer will not be started." << endl; |
|
exit(1); |
} | } |
| |
// |
// Get the connection port configurations |
// Check the log trace options and set global variable |
|
// |
|
Boolean pegasusIOLog = false; |
|
| |
if (String::equal(configManager->getCurrentValue("logtrace"), "true")) |
Uint32 portNumberHttps; |
{ |
Uint32 portNumberHttp; |
pegasusIOLog = true; |
|
} |
|
Boolean useSSL = false; |
|
| |
if (String::equal(configManager->getCurrentValue("SSL"), "true")) |
if (enableHttpsConnection) |
{ | { |
useSSL = true; |
String httpsPort = configManager->getCurrentValue("httpsPort"); |
} |
CString portString = httpsPort.getCString(); |
|
char* end = 0; |
|
Uint32 port = strtol(portString, &end, 10); |
|
assert(end != 0 && *end == '\0'); |
| |
// mdh: need to get the environment for the Windows Service to run |
// |
const char* tmp = getenv("PEGASUS_HOME"); |
// Look up the WBEM-HTTPS port number |
if (tmp) |
// |
{ |
portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port); |
pegasusHome = tmp; |
|
} | } |
ConfigManager::setPegasusHome(pegasusHome); |
|
|
|
// Grab the port otpion: |
|
| |
String portOption; |
if (enableHttpConnection) |
|
|
if (useSSL) |
|
{ |
|
portOption = configManager->getCurrentValue("httpsPort"); |
|
} |
|
else |
|
{ | { |
portOption = configManager->getCurrentValue("httpPort"); |
String httpPort = configManager->getCurrentValue("httpPort"); |
|
CString portString = httpPort.getCString(); |
|
char* end = 0; |
|
Uint32 port = strtol(portString, &end, 10); |
|
assert(end != 0 && *end == '\0'); |
|
|
|
// |
|
// Look up the WBEM-HTTP port number |
|
// |
|
portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port); |
} | } |
CString address = portOption.getCString(); |
|
| |
// Set up the Logger | // Set up the Logger |
Logger::setHomeDirectory("./logs"); |
String logsDirectory = String::EMPTY; |
|
logsDirectory = configManager->getCurrentValue("logdir"); |
|
logsDirectory = ConfigManager::getHomedPath(configManager->getCurrentValue("logdir")); |
|
|
|
Logger::setHomeDirectory(logsDirectory); |
| |
// Put server start message to the logger | // Put server start message to the logger |
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
Logger::put(Logger::STANDARD_LOG, PEGASUS_SERVICE_NAME, Logger::INFORMATION, |
"Start $0 %1 port $2 $3 ", 88, PEGASUS_NAME, PEGASUS_VERSION, |
"Started $0 version $1.", PEGASUS_NAME, PEGASUS_VERSION); |
(const char*)address, (pegasusIOTrace ? " Tracing": " ")); |
|
// try loop to bind the address, and run the server | // try loop to bind the address, and run the server |
try | try |
{ | { |
Monitor monitor; |
Monitor monitor(true); |
| |
CIMServer server(&monitor, useSSL); |
CIMServer server(&monitor); |
server_windows = &server; | server_windows = &server; |
| |
char* end = 0; |
if (enableHttpConnection) |
long portNumber = strtol(address, &end, 10); |
{ |
assert(end != 0 && *end == '\0'); |
server_windows->addAcceptor(false, portNumberHttp, false); |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"Listening on HTTP port $0.", portNumberHttp); |
|
} |
|
if (enableHttpsConnection) |
|
{ |
|
server_windows->addAcceptor(false, portNumberHttps, true); |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"Listening on HTTPS port $0.", portNumberHttps); |
|
} |
| |
server_windows->bind(portNumber); |
server_windows->bind(); |
| |
while(!server_windows->terminated()) | while(!server_windows->terminated()) |
{ | { |
|
|
} | } |
| |
| |
///////////////////////////////////////////////////////////////// |
//------------------------------------------------------------------------- |
// Windows NT Service Control Code | // Windows NT Service Control Code |
///////////////////////////////////////////////////////////////// |
//------------------------------------------------------------------------- |
|
|
|
//------------------------------------------------------------------------- |
|
// SERVICE (no parameters) |
|
//------------------------------------------------------------------------- |
|
void cim_server_service(int argc, char **argv) |
|
{ |
|
Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS; |
|
char console_title[_MAX_PATH] = {0}; |
| |
|
// Check if running from a console window |
|
if (GetConsoleTitle(console_title, _MAX_PATH) > 0) |
|
return; |
|
|
|
pegasus_service_event = CreateEvent(NULL, FALSE, FALSE, NULL); |
| |
|
// Run should exit the process if a service |
|
status = pegasus_service.Run(cimserver_windows_main); |
| |
|
// If we made it here there was a problem starting this process as a service |
|
// Log the problem to the log file |
|
|
|
// TODO: log or echo something here |
|
} |
| |
VOID WINAPI cimserver_windows_main(int argc, char **argv) |
//------------------------------------------------------------------------- |
|
// START/STOP handler |
|
//------------------------------------------------------------------------- |
|
int cimserver_windows_main(int flag, int argc, char *argv[]) |
{ | { |
int ccode; |
switch (flag) |
SERVICE_TABLE_ENTRY dispatch_table[] = |
|
{ | { |
{"cimserver", cimserver_service_start}, |
case Service::STARTUP_FLAG: |
{NULL, NULL} |
if (_beginthread(cimserver_windows_thread, 0, NULL)) |
}; |
WaitForSingleObject(pegasus_service_event, INFINITE); |
|
break; |
| |
/* let everyone know we are running (or trying to run) as an NT service */ |
case Service::SHUTDOWN_FLAG: |
if(!(ccode = StartServiceCtrlDispatcher(dispatch_table))) |
SetEvent(pegasus_service_event); |
{ |
break; |
ccode = GetLastError(); |
|
// Put server start message to the logger |
default: |
Logger::put(Logger::STANDARD_LOG, "CIMServer_Windows", Logger::INFORMATION, |
break; |
"Started as a Windows Service"); |
|
} |
|
return; |
|
} | } |
| |
///////////////////////////////////////////////////////////////// |
return 0; |
// |
} |
// called by the NT service control manager to start the SLP service |
|
// |
|
///////////////////////////////////////////////////////////////// |
|
| |
VOID WINAPI cimserver_service_start(DWORD argc, LPTSTR *argv) |
//------------------------------------------------------------------------- |
|
// IS RUNNING? |
|
//------------------------------------------------------------------------- |
|
Boolean isCIMServerRunning(void) |
{ | { |
|
Service::State state; |
|
pegasus_service.GetState(&state); |
| |
DWORD status; |
return (state == Service::SERVICE_STATE_RUNNING) ? true : false; |
DWORD specificError; |
} |
pegasus_status.dwServiceType = SERVICE_WIN32; |
|
pegasus_status.dwCurrentState = SERVICE_START_PENDING; |
|
pegasus_status.dwControlsAccepted |
|
= SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN ; |
|
pegasus_status.dwWin32ExitCode = 0; |
|
pegasus_status.dwServiceSpecificExitCode = 0; |
|
pegasus_status.dwCheckPoint = 0; |
|
pegasus_status.dwWaitHint = 0; |
|
| |
pegasus_status_handle = RegisterServiceCtrlHandler("cimserver", cimserver_service_ctrl_handler); |
//------------------------------------------------------------------------- |
if( pegasus_status_handle == (SERVICE_STATUS_HANDLE)0) |
// INSTALL |
|
//------------------------------------------------------------------------- |
|
bool cimserver_install_nt_service(char *service_name) |
{ | { |
Logger::put(Logger::STANDARD_LOG, "CIMServer_Windows", Logger::INFORMATION, |
Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS; |
"Error installing service handler"); |
char filename[_MAX_PATH] = {0}; |
return; |
char displayname[_MAX_PATH] = {0}; |
} |
|
| |
// mdday -- I need to replace this hack with registry code |
// If service name is specified, override default |
|
if (service_name == NULL) |
|
{ |
|
strcpy(displayname, PEGASUS_DISPLAY_NAME); |
|
} |
|
else |
|
{ |
|
pegasus_service.SetServiceName(service_name); |
|
sprintf(displayname, "%s - %s", PEGASUS_DISPLAY_NAME, service_name); |
|
} |
| |
// this is an ugly hack because we should really be getting this data |
GetModuleFileName(NULL, filename, sizeof(filename)); |
// out of the registry. We are essentially forcing pegasus to be run |
status = pegasus_service.Install(displayname, PEGASUS_DESCRIPTION, filename); |
// from its build tree. i.e.: |
|
// PEGASUS_HOME = binary_exe_path minus "\bin\cimserver.exe" |
|
| |
// so if my build environment is in "c:\my-programs\pegasus\ |
// Upon success, set home in registry |
// I will install the service binary path as "c:\my-programs\pegasus\bin\cimserver.exe" |
if (status == Service::SERVICE_RETURN_SUCCESS) |
// Therefore I will derive PEGASUS_HOME as "c:\my-programs\pegasus" |
{ |
|
char pegasus_homepath[_MAX_PATH]; |
|
System::extract_file_path(filename, pegasus_homepath); |
|
pegasus_homepath[strlen(pegasus_homepath)-1] = '\0'; |
|
strcpy(filename, pegasus_homepath); |
|
System::extract_file_path(filename, pegasus_homepath); |
|
pegasus_homepath[strlen(pegasus_homepath)-1] = '\0'; |
|
_setRegInfo(g_cimservice_home, pegasus_homepath); |
|
} |
| |
// If I do something wierd and run pegasus from "c:\winnt" then this hack will break |
return (status == Service::SERVICE_RETURN_SUCCESS) ? true : false; |
// the service will think its running but the CIMServer object will never have been instantiated. |
} |
| |
SC_HANDLE service_handle, sc_manager; |
//------------------------------------------------------------------------- |
if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))) |
// REMOVE |
|
//------------------------------------------------------------------------- |
|
bool cimserver_remove_nt_service(char *service_name) |
{ | { |
if(NULL != (service_handle = OpenService(sc_manager, |
Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS; |
"cimserver", |
|
SERVICE_ALL_ACCESS))) |
|
| |
|
// If service name is specified, override default |
|
if (service_name != NULL) |
{ | { |
DWORD bytes_needed = 0; |
pegasus_service.SetServiceName(service_name); |
QUERY_SERVICE_CONFIG *svc_config = NULL; |
} |
| |
QueryServiceConfig(service_handle, svc_config, sizeof(svc_config), &bytes_needed); |
status = pegasus_service.Remove(); |
if(bytes_needed > 0) |
|
{ |
return (status == Service::SERVICE_RETURN_SUCCESS) ? true : false; |
if(NULL != ( svc_config = (QUERY_SERVICE_CONFIG *) malloc(bytes_needed))) |
} |
{ |
|
if(TRUE == QueryServiceConfig(service_handle, svc_config, bytes_needed, &bytes_needed)) |
//------------------------------------------------------------------------- |
|
// START |
|
//------------------------------------------------------------------------- |
|
bool cimserver_start_nt_service(char *service_name) |
{ | { |
Uint32 position; |
Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS; |
runPath = new String(svc_config->lpBinaryPathName); |
|
if(PEG_NOT_FOUND != (position = runPath->reverseFind('\\'))) |
// If service name is specified, override default |
|
if (service_name != NULL) |
{ | { |
Uint32 len = runPath->size(); |
pegasus_service.SetServiceName(service_name); |
runPath->remove(position, len - position); |
|
position = runPath->reverseFind('\\'); |
|
len = runPath->size(); |
|
runPath->remove(position, len - position); |
|
} |
|
} |
|
free(svc_config); |
|
} | } |
|
|
|
status = pegasus_service.Start(5); |
|
|
|
return (status == Service::SERVICE_RETURN_SUCCESS) ? true : false; |
} | } |
CloseServiceHandle(service_handle); |
|
|
//------------------------------------------------------------------------- |
|
// STOP |
|
//------------------------------------------------------------------------- |
|
bool cimserver_stop_nt_service(char *service_name) |
|
{ |
|
Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS; |
|
|
|
// If service name is specified, override default |
|
if (service_name != NULL) |
|
{ |
|
pegasus_service.SetServiceName(service_name); |
} | } |
CloseServiceHandle(sc_manager); |
|
|
status = pegasus_service.Stop(5); |
|
|
|
return (status == Service::SERVICE_RETURN_SUCCESS) ? true : false; |
} | } |
| |
status = cimserver_initialization(argc, argv, &specificError); |
//------------------------------------------------------------------------- |
if(status < 0) |
// HELPER Utilities |
|
//------------------------------------------------------------------------- |
|
static bool _getRegInfo(const char *lpchKeyword, char *lpchRetValue) |
{ | { |
pegasus_status.dwCurrentState = SERVICE_STOPPED; |
HKEY hKey; |
pegasus_status.dwCheckPoint = 0; |
DWORD dw = _MAX_PATH; |
pegasus_status.dwWaitHint = 0; |
char subKey[_MAX_PATH] = {0}; |
pegasus_status.dwWin32ExitCode = status; |
|
pegasus_status.dwServiceSpecificExitCode = specificError; |
|
SetServiceStatus(pegasus_status_handle, &pegasus_status); |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer_Windows", Logger::INFORMATION, |
|
"Error starting Cim Server"); |
|
return; |
|
} |
|
| |
pegasus_status.dwCurrentState = SERVICE_RUNNING; |
sprintf(subKey, g_cimservice_key, pegasus_service.GetServiceName()); |
pegasus_status.dwCheckPoint = 0; |
|
pegasus_status.dwWaitHint = 0; |
|
| |
if(!SetServiceStatus(pegasus_status_handle, &pegasus_status)) |
if ((RegOpenKeyEx(HKEY_LOCAL_MACHINE, |
|
subKey, |
|
0, |
|
KEY_READ, |
|
&hKey)) != ERROR_SUCCESS) |
{ | { |
if(server_windows != NULL) |
return false; |
server_windows->shutdown(); |
|
} | } |
| |
return; |
if ((RegQueryValueEx(hKey, |
|
lpchKeyword, |
|
NULL, |
|
NULL, |
|
(LPBYTE)lpchRetValue, |
|
&dw)) != ERROR_SUCCESS) |
|
{ |
|
RegCloseKey(hKey); |
|
return false; |
} | } |
| |
VOID WINAPI cimserver_service_ctrl_handler(DWORD opcode) |
RegCloseKey(hKey); |
{ |
|
| |
switch(opcode) { |
return true; |
case SERVICE_CONTROL_STOP: |
|
case SERVICE_CONTROL_SHUTDOWN: |
|
if(server_windows != NULL) |
|
server_windows->shutdown(); |
|
pegasus_status.dwCurrentState = SERVICE_STOPPED; |
|
pegasus_status.dwCheckPoint = 0; |
|
pegasus_status.dwWaitHint = 0; |
|
pegasus_status.dwWin32ExitCode = 0; |
|
SetServiceStatus(pegasus_status_handle, &pegasus_status); |
|
return; |
|
break; |
|
default: |
|
break; |
|
} |
|
SetServiceStatus(pegasus_status_handle, &pegasus_status); |
|
return; |
|
} | } |
| |
DWORD cimserver_initialization(DWORD argc, LPTSTR *argv, DWORD *specificError) |
static bool _setRegInfo(const char *lpchKeyword, const char *lpchValue) |
{ | { |
|
HKEY hKey; |
|
DWORD dw = _MAX_PATH; |
|
char home_key[_MAX_PATH] = {0}; |
|
char subKey[_MAX_PATH] = {0}; |
| |
return( _beginthread(cimserver_windows_thread, 0, NULL )); |
if (lpchKeyword == NULL || lpchValue == NULL) |
} |
return false; |
| |
|
sprintf(subKey, g_cimservice_key, pegasus_service.GetServiceName()); |
| |
Uint32 cimserver_install_nt_service(String &pegasusHome ) |
if ((RegCreateKeyEx (HKEY_LOCAL_MACHINE, |
|
subKey, |
|
0, |
|
NULL, |
|
0, |
|
KEY_ALL_ACCESS, |
|
NULL, |
|
&hKey, |
|
NULL) != ERROR_SUCCESS)) |
{ | { |
SC_HANDLE service_handle, sc_manager; |
return false; |
Uint32 ccode = 0; |
|
pegasusHome.append("\\bin\\cimserver.exe"); |
|
CString pegHome = pegasusHome.getCString() ; |
|
LPCSTR path_name = (const char*) pegHome; |
|
if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))) |
|
{ |
|
if(NULL != (service_handle = CreateService(sc_manager, |
|
"cimserver", |
|
"Pegasus CIM Object Manager", |
|
SERVICE_ALL_ACCESS, |
|
SERVICE_WIN32_OWN_PROCESS, |
|
SERVICE_DEMAND_START, |
|
SERVICE_ERROR_NORMAL, |
|
path_name, |
|
NULL, NULL, NULL, NULL, NULL))) |
|
{ |
|
ccode = (Uint32)service_handle; |
|
} | } |
CloseServiceHandle(service_handle); |
|
|
if ((RegSetValueEx(hKey, |
|
lpchKeyword, |
|
0, |
|
REG_SZ, |
|
(CONST BYTE *)lpchValue, |
|
(DWORD)(strlen(lpchValue)+1))) != ERROR_SUCCESS) |
|
{ |
|
RegCloseKey(hKey); |
|
return false; |
} | } |
| |
return(ccode); |
RegCloseKey(hKey); |
|
|
|
return true; |
} | } |
| |
Uint32 cimserver_remove_nt_service(void) |
void setHome(String & home) |
|
{ |
|
// Determine the absolute path to the running program |
|
char exe_pathname[_MAX_PATH] = {0}; |
|
char home_pathname[_MAX_PATH] = {0}; |
|
GetModuleFileName(NULL, exe_pathname, sizeof(exe_pathname)); |
|
|
|
// Pegasus home search rules: |
|
// - look in registry (if set) |
|
// - if not found, look in PEGASUS_HOME (if set) |
|
// - if not found, use exe directory minus one level |
|
|
|
bool found_reg = _getRegInfo("home", home_pathname); |
|
if (found_reg == true) |
{ | { |
|
// Make sure home matches |
|
String current_home(home_pathname); |
|
String current_exe(exe_pathname); |
|
current_home.toLower(); |
|
current_exe.toLower(); |
| |
SC_HANDLE service_handle, sc_manager; |
Uint32 pos = current_exe.find(current_home); |
int ccode = 0; |
if (pos != PEG_NOT_FOUND) |
if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))) |
{ |
|
home = home_pathname; |
|
} |
|
else |
|
{ |
|
found_reg = false; |
|
} |
|
} |
|
if (found_reg == false) |
|
{ |
|
const char* tmp = getenv("PEGASUS_HOME"); |
|
if (tmp) |
{ | { |
if(NULL != (service_handle = OpenService(sc_manager, "cimserver", DELETE))) |
home = tmp; |
|
} |
|
else |
{ | { |
DeleteService(service_handle); |
// ASSUMPTION: At a minimum, the cimserver program is running |
CloseServiceHandle(service_handle); |
// from a "bin" directory |
ccode = 1; |
home = FileSystem::extractFilePath(exe_pathname); |
|
home.remove(home.size()-1, 1); |
|
home = FileSystem::extractFilePath(home); |
|
home.remove(home.size()-1, 1); |
} | } |
CloseServiceHandle(sc_manager); |
|
} | } |
return(ccode); |
|
} | } |
|
|