version 1.67, 2002/08/27 18:14:47
|
version 1.79, 2002/10/15 21:41:03
|
|
|
// Modified By: Jenny Yu (jenny_yu@hp.com) | // Modified By: Jenny Yu (jenny_yu@hp.com) |
// | // |
// Modified By: Sushma Fernandes (sushma_fernandes@hp.com) | // Modified By: Sushma Fernandes (sushma_fernandes@hp.com) |
|
// Carol Ann Krug Graves, Hewlett-Packard Company |
|
// (carolann_graves@hp.com) |
|
// Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
| |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
#include <Pegasus/Common/Constants.h> | #include <Pegasus/Common/Constants.h> |
#include <Pegasus/suballoc/suballoc.h> |
|
#include <iostream> | #include <iostream> |
#include <cassert> | #include <cassert> |
#include <cstdlib> | #include <cstdlib> |
|
|
#include <Pegasus/Client/CIMClient.h> | #include <Pegasus/Client/CIMClient.h> |
#include <Pegasus/Server/ShutdownService.h> | #include <Pegasus/Server/ShutdownService.h> |
#include <Pegasus/Common/Destroyer.h> | #include <Pegasus/Common/Destroyer.h> |
#if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) |
#if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP) |
#include <slp/slp.h> | #include <slp/slp.h> |
#endif | #endif |
| |
|
|
// | // |
// set client timeout to 2 seconds | // set client timeout to 2 seconds |
// | // |
client.setTimeOut(2000); |
client.setTimeout(2000); |
} | } |
catch(Exception& e) | catch(Exception& e) |
{ | { |
|
|
// | // |
String referenceStr = "//"; | String referenceStr = "//"; |
referenceStr.append(hostStr); | referenceStr.append(hostStr); |
referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN); |
referenceStr.append("/"); |
|
referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString()); |
referenceStr.append(":"); | referenceStr.append(":"); |
referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN); |
referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString()); |
CIMObjectPath reference(referenceStr); | CIMObjectPath reference(referenceStr); |
| |
// | // |
|
|
// | // |
// check to see if user is root | // check to see if user is root |
// | // |
|
#ifndef PEGASUS_OS_OS400 |
if (!System::isPrivilegedUser(System::getEffectiveUserName())) | if (!System::isPrivilegedUser(System::getEffectiveUserName())) |
{ | { |
cout << "You must have superuser privilege to run "; | cout << "You must have superuser privilege to run "; |
cout << "cimserver." << endl; | cout << "cimserver." << endl; |
exit(0); | exit(0); |
} | } |
|
#endif |
| |
// | // |
// Check to see if shutdown has already been specified: | // Check to see if shutdown has already been specified: |
|
|
{ | { |
String configTimeout = | String configTimeout = |
configManager->getCurrentValue("shutdownTimeout"); | configManager->getCurrentValue("shutdownTimeout"); |
ArrayDestroyer<char> timeoutCString(configTimeout.allocateCString()); |
timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10); |
timeoutValue = strtol(timeoutCString.getPointer(), (char **)0, 10); |
|
| |
shutdownCIMOM(timeoutValue); | shutdownCIMOM(timeoutValue); |
| |
|
|
useSLP = true; | useSLP = true; |
} | } |
| |
|
#if defined(PEGASUS_USE_RELEASE_CONFIG_OPTIONS) |
|
Boolean enableHttpConnection = String::equal( |
|
configManager->getCurrentValue("enableHttpConnection"), "true"); |
|
Boolean enableHttpsConnection = String::equal( |
|
configManager->getCurrentValue("enableHttpsConnection"), "true"); |
|
|
|
if (enableHttpConnection && enableHttpsConnection) |
|
{ |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, |
|
"Enabling both HTTP and HTTPS connections is unsupported. " |
|
"Only the HTTPS connection is enabled."); |
|
cerr << "Enabling both HTTP and HTTPS connections is unsupported. " |
|
"Only the HTTPS connection is enabled." << endl; |
|
} |
|
else if (!enableHttpConnection && !enableHttpsConnection) |
|
{ |
|
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); |
|
} |
|
|
|
useSSL = enableHttpsConnection; |
|
|
|
#else |
if (String::equal(configManager->getCurrentValue("SSL"), "true")) | if (String::equal(configManager->getCurrentValue("SSL"), "true")) |
{ | { |
useSSL = true; | useSSL = true; |
} | } |
|
#endif |
} | } |
catch (UnrecognizedConfigProperty e) | catch (UnrecognizedConfigProperty e) |
{ | { |
|
|
| |
if (useSSL) | if (useSSL) |
{ | { |
char* p = httpsPort.allocateCString(); |
|
char* end = 0; | char* end = 0; |
Uint32 port = strtol(p, &end, 10); |
CString portString = httpsPort.getCString(); |
|
Uint32 port = strtol(portString, &end, 10); |
assert(end != 0 && *end == '\0'); | assert(end != 0 && *end == '\0'); |
delete [] p; |
|
| |
// | // |
// Look up the WBEM-HTTPS port number | // Look up the WBEM-HTTPS port number |
|
|
} | } |
else | else |
{ | { |
char* p = httpPort.allocateCString(); |
|
char* end = 0; | char* end = 0; |
Uint32 port = strtol(p, &end, 10); |
CString portString = httpPort.getCString(); |
|
Uint32 port = strtol(portString, &end, 10); |
assert(end != 0 && *end == '\0'); | assert(end != 0 && *end == '\0'); |
delete [] p; |
|
| |
// | // |
// Look up the WBEM-HTTP port number | // Look up the WBEM-HTTP port number |
|
|
| |
#ifdef PEGASUS_OS_HPUX | #ifdef PEGASUS_OS_HPUX |
umask(S_IWGRP|S_IWOTH); | 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(isCIMServerRunning()) |
|
{ |
|
cout << "Unable to start CIMServer." << endl; |
|
cout << "CIMServer is already running." << endl; |
|
|
|
// |
|
// notify parent process (if there is a parent process) to terminate |
|
// |
|
if (daemonOption) |
|
notify_parent(); |
|
|
|
exit(1); |
|
} |
|
|
#endif | #endif |
| |
// try loop to bind the address, and run the server | // try loop to bind the address, and run the server |
try | try |
{ | { |
#if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) |
#if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP) |
slp_client *discovery = new slp_client() ;; | slp_client *discovery = new slp_client() ;; |
String serviceURL; | String serviceURL; |
serviceURL.assign("service:cim.pegasus://"); | serviceURL.assign("service:cim.pegasus://"); |
|
|
serviceURL.append(host_name); | serviceURL.append(host_name); |
serviceURL.append(":"); | serviceURL.append(":"); |
serviceURL.append(address); | serviceURL.append(address); |
char *url = serviceURL.allocateCString(); |
|
// free(host_name); |
|
#endif | #endif |
| |
Monitor monitor(true); | Monitor monitor(true); |
|
|
| |
server.bind(portNumber); | server.bind(portNumber); |
| |
|
// notify parent process (if there is a parent process) to terminate |
|
// so user knows that cimserver is ready to serve CIM requests. |
|
if (daemonOption) |
|
notify_parent(); |
|
|
time_t last = 0; | time_t last = 0; |
| |
#if defined(PEGASUS_OS_HPUX) | #if defined(PEGASUS_OS_HPUX) |
|
|
// | // |
while( !server.terminated() ) | while( !server.terminated() ) |
{ | { |
#if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) |
#if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP) |
if(useSLP ) | if(useSLP ) |
{ | { |
if( (time(NULL) - last ) > 60 ) | if( (time(NULL) - last ) > 60 ) |
{ | { |
if( discovery != NULL && url != NULL ) |
if( discovery != NULL && serviceURL.size() ) |
discovery->srv_reg_all(url, |
discovery->srv_reg_all(serviceURL.getCString(), |
"(namespace=root/cimv2)", | "(namespace=root/cimv2)", |
"service:cim.pegasus", | "service:cim.pegasus", |
"DEFAULT", | "DEFAULT", |
|
|
catch(Exception& e) | catch(Exception& e) |
{ | { |
PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); | PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); |
|
|
|
// |
|
// notify parent process (if there is a parent process) to terminate |
|
// |
|
if (daemonOption) |
|
notify_parent(); |
|
|
return 1; | return 1; |
} | } |
| |