version 1.65, 2002/08/17 00:09:38
|
version 1.78, 2002/10/09 22:05:02
|
|
|
// 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 |
| |
|
|
#if defined(PEGASUS_OS_TYPE_WINDOWS) | #if defined(PEGASUS_OS_TYPE_WINDOWS) |
# include "cimserver_windows.cpp" | # include "cimserver_windows.cpp" |
#elif defined(PEGASUS_OS_TYPE_UNIX) | #elif defined(PEGASUS_OS_TYPE_UNIX) |
|
# if defined(PEGASUS_OS_OS400) |
|
# include "cimserver_os400.cpp" |
|
# else |
# include "cimserver_unix.cpp" | # include "cimserver_unix.cpp" |
|
#endif |
#else | #else |
# error "Unsupported platform" | # error "Unsupported platform" |
#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) |
{ | { |
PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl); | PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl); |
PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl); | PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl); |
|
#ifdef PEGASUS_OS_OS400 |
|
// The server job may still be active but not responding. |
|
// Kill the job if it exists. |
|
cimserver_kill(); |
|
#endif |
exit(0); | exit(0); |
} | } |
| |
|
|
// | // |
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); |
| |
// | // |
|
|
{ | { |
PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl); | PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl); |
} | } |
|
#ifdef PEGASUS_OS_OS400 |
|
// Kill the server job. |
|
cimserver_kill(); |
|
#endif |
exit(1); | exit(1); |
} | } |
catch(Exception& e) | catch(Exception& e) |
|
|
Boolean shutdownOption = false; | Boolean shutdownOption = false; |
Uint32 timeoutValue = 0; | Uint32 timeoutValue = 0; |
| |
|
#ifdef PEGASUS_OS_OS400 |
|
// Initialize Pegasus home to the shipped OS/400 directory. |
|
pegasusHome = OS400_DEFAULT_PEGASUS_HOME; |
|
#endif |
|
|
// | // |
// Get environment variables: | // Get environment variables: |
// | // |
|
|
// | // |
// 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 |
|
|
exit(-1); | exit(-1); |
} | } |
| |
|
#ifdef PEGASUS_OS_OS400 |
|
// Special server initialization code for OS/400. |
|
if (cimserver_initialize() != 0) |
|
{ |
|
// do some logging here! |
|
exit(-1); |
|
} |
|
#endif |
|
|
#ifdef PEGASUS_OS_HPUX | #ifdef PEGASUS_OS_HPUX |
umask(S_IWGRP|S_IWOTH); | umask(S_IWGRP|S_IWOTH); |
#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://"); |
String host_name = slp_get_host_name(); | String host_name = slp_get_host_name(); |
serviceURL += host_name; |
serviceURL.append(host_name); |
serviceURL += ":"; |
serviceURL.append(":"); |
serviceURL += 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; |
} | } |
| |