version 1.191.2.4, 2006/12/29 17:47:32
|
version 1.191.2.5, 2006/12/29 22:22:04
|
|
|
# include <fcntl.h> | # include <fcntl.h> |
#endif | #endif |
| |
PEGASUS_USING_PEGASUS; |
|
PEGASUS_USING_STD; |
|
|
|
#ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION | #ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION |
|
# include <Pegasus/ExecutorClient/ExecutorClient.h> |
# define PEGASUS_PROCESS_NAME "cimservermain"; | # define PEGASUS_PROCESS_NAME "cimservermain"; |
#else | #else |
# define PEGASUS_PROCESS_NAME "cimserver"; | # define PEGASUS_PROCESS_NAME "cimserver"; |
#endif | #endif |
| |
|
PEGASUS_USING_PEGASUS; |
|
PEGASUS_USING_STD; |
|
|
//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 |
|
|
| |
static void _checkForExecutor(const char* arg0) | static void _checkForExecutor(const char* arg0) |
{ | { |
#if 0 |
if (!getenv("PEGASUS_EXECUTOR_SOCKET")) |
int uid = getuid(); |
|
int gid = getgid(); |
|
printf("%s: uid=%d, gid=%d\n", arg0, uid, gid); |
|
#endif |
|
|
|
// If the executor started this process, then it created and passed a |
|
// socket descriptor to this process with a value of three. To test this, |
|
// we open a file an check that its file descriptor is four. If not, then |
|
// the executor did not create this process. |
|
|
|
FILE* fs = tmpfile(); |
|
|
|
if (!fs) |
|
{ |
|
fprintf(stderr, "%s: tmpfile() failed()\n", arg0); |
|
exit(1); |
|
} |
|
|
|
if (fileno(fs) != 4) |
|
{ | { |
fprintf(stderr, "%s: do not be run this program directly. " |
fprintf(stderr, "%s: do not run this program directly. " |
"It is part of the cimserver program.\n", arg0); | "It is part of the cimserver program.\n", arg0); |
exit(1); | exit(1); |
} | } |
|
|
fclose(fs); |
|
} | } |
| |
#endif /* PEGASUS_ENABLE_PRIVILEGE_SEPARATION */ | #endif /* PEGASUS_ENABLE_PRIVILEGE_SEPARATION */ |
|
|
// 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 |
} | } |
| |
|
|
} | } |
// 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) |
|
ExecutorClient::daemonizeExecutor(); |
|
#else |
if (daemonOption) | if (daemonOption) |
_cimServerProcess->notify_parent(0); | _cimServerProcess->notify_parent(0); |
|
#endif |
| |
time_t last = 0; | time_t last = 0; |
| |