version 1.191, 2006/11/29 22:09:32
|
version 1.191.2.11, 2007/01/04 01:46:28
|
|
|
# include <fcntl.h> | # include <fcntl.h> |
#endif | #endif |
| |
|
#ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION |
|
# include <Pegasus/Common/Executor.h> |
|
# define PEGASUS_PROCESS_NAME "cimservermain" |
|
#else |
|
# define PEGASUS_PROCESS_NAME "cimserver" |
|
#endif |
|
|
PEGASUS_USING_PEGASUS; | PEGASUS_USING_PEGASUS; |
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
#define PEGASUS_PROCESS_NAME "cimserver"; |
|
|
|
//Windows service variables are not defined elsewhere in the product | //Windows service variables are not defined elsewhere in the product |
//enable ability to override these | //enable ability to override these |
#ifndef PEGASUS_SERVICE_NAME | #ifndef PEGASUS_SERVICE_NAME |
|
|
exit(1); | exit(1); |
#endif | #endif |
} | } |
catch(Exception&) |
catch(Exception& e) |
{ | { |
|
cerr << "Shutdown failed: " << e.getMessage() << endl; |
// | // |
// This may mean that the CIM Server has terminated, causing this | // This may mean that the CIM Server has terminated, causing this |
// client to get a "Empty HTTP response message" exception. It may | // client to get a "Empty HTTP response message" exception. It may |
|
|
return; | return; |
} | } |
| |
|
#ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION |
|
|
|
static int _extractExecutorSockOpt(int& argc, char**& argv) |
|
{ |
|
// Extract the "-x <sock>" option if any. This indicates that the |
|
// e[x]ecutor is running. The option argument is the socket used |
|
// to communicate with the executor. Remove the option from the |
|
// argv list and decrease argc by two. |
|
|
|
int sock = -1; |
|
|
|
for (int i = 1; i < argc; i++) |
|
{ |
|
if (strcmp(argv[i], "-x") == 0) |
|
{ |
|
// Check for missing option argument. |
|
|
|
if (i + 1 == argc) |
|
{ |
|
fprintf(stderr, |
|
"%s: missing option argument for -x\n", argv[0]); |
|
exit(1); |
|
} |
|
|
|
// Convert argument to integer. |
|
|
|
char* end; |
|
unsigned long x = strtoul(argv[i+1], &end, 10); |
|
|
|
// Check whether option argument will fit in integer. |
|
|
|
if (*end != '\0' || x > 2147483647) |
|
{ |
|
fprintf(stderr, |
|
"%s: bad -x option argument: %s\n", argv[0], argv[i+1]); |
|
exit(1); |
|
} |
|
|
|
sock = int(x); |
|
|
|
// Remove "-x <sock>" from argv-argc. |
|
|
|
memmove(argv + i, argv + i + 2, sizeof(char*) * (argc - i - 1)); |
|
argc -= 2; |
|
break; |
|
} |
|
} |
|
|
|
return sock; |
|
} |
|
|
|
#endif /* PEGASUS_ENABLE_PRIVILEGE_SEPARATION */ |
| |
///////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////// |
// MAIN | // MAIN |
////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////// |
|
|
int main(int argc, char** argv) | int main(int argc, char** argv) |
{ | { |
|
#ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION |
|
|
|
// Check for fingerprint (passed only by the executor). |
|
|
|
if (argc < 2 || strcmp(argv[1], EXECUTOR_FINGERPRINT) != 0) |
|
{ |
|
cerr << argv[0]; |
|
cerr << ": This is an internal Pegasus program; "; |
|
cerr << "please do not execute it directly. " << endl; |
|
exit(1); |
|
} |
|
|
|
// Remove argv[1] (the fingerprint). |
|
|
|
memcpy(argv + 1, argv + 2, sizeof(char*) * (argc - 1)); |
|
argc--; |
|
|
|
// If invoked with "-x <socket>" option, then use executor client. |
|
|
|
Executor::setSock(_extractExecutorSockOpt(argc, argv)); |
|
|
|
// Ping executor to be sure the sock was valid. |
|
|
|
if (Executor::ping() != 0) |
|
{ |
|
fprintf(stderr, |
|
"%s: failed to ping executor on socket given by -x option\n", |
|
argv[0]); |
|
exit(1); |
|
} |
|
|
|
#endif |
|
|
String pegasusHome = String::EMPTY; | String pegasusHome = String::EMPTY; |
Boolean shutdownOption = false; | Boolean shutdownOption = false; |
Boolean debugOutputOption = false; | Boolean debugOutputOption = false; |
|
|
{ | { |
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, | Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
"src.Server.cimserver.SERVER_NOT_STARTED", | "src.Server.cimserver.SERVER_NOT_STARTED", |
"cimserver not started: $0", e.getMessage()); |
"MEB:T2 cimserver not started: $0", e.getMessage()); |
| |
#if !defined(PEGASUS_OS_OS400) | #if !defined(PEGASUS_OS_OS400) |
MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED", | MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED", |
"cimserver not started: $0", e.getMessage()); |
"MEB:T3 cimserver not started: $0", e.getMessage()); |
| |
PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms) | PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms) |
<< PEGASUS_STD(endl); | << PEGASUS_STD(endl); |
|
|
// Get the parent's PID before forking | // Get the parent's PID before forking |
_cimServerProcess->set_parent_pid(System::getPID()); | _cimServerProcess->set_parent_pid(System::getPID()); |
| |
// do we need to run as a daemon ? |
// Do not fork when using privilege separation (executor will daemonize itself |
|
// later). |
if (daemonOption) | if (daemonOption) |
{ | { |
if(-1 == _cimServerProcess->cimserver_fork()) | if(-1 == _cimServerProcess->cimserver_fork()) |
#ifndef PEGASUS_OS_OS400 | #ifndef PEGASUS_OS_OS400 |
{ |
|
return(-1); | return(-1); |
} |
|
#else | #else |
{ |
|
return(-1); | return(-1); |
} |
|
else | else |
{ |
|
return(0); | return(0); |
} |
|
#endif | #endif |
|
|
} | } |
| |
// l10n | // l10n |
|
|
} | } |
// notify parent process (if there is a parent process) to terminate | // notify parent process (if there is a parent process) to terminate |
// so user knows that there is cimserver ready to serve CIM requests. | // so user knows that there is cimserver ready to serve CIM requests. |
|
#if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) |
|
if (daemonOption) |
|
Executor::daemonizeExecutor(); |
|
#else |
if (daemonOption) | if (daemonOption) |
_cimServerProcess->notify_parent(0); | _cimServerProcess->notify_parent(0); |
|
#endif |
| |
time_t last = 0; | time_t last = 0; |
| |
|
|
#endif | #endif |
| |
| |
|
/* |
|
ATTN:MEB: |
|
*/ |
| |
// | // |
// Loop to call CIMServer's runForever() method until CIMServer | // Loop to call CIMServer's runForever() method until CIMServer |
|
|
deleteCIMServer(); | deleteCIMServer(); |
return 0; | return 0; |
} | } |
|
|
|
|
|
|
|
|