version 1.15, 2005/02/27 04:10:53
|
version 1.21, 2005/11/18 18:38:35
|
|
|
#else | #else |
# include <unistd.h> // For fork(), exec(), and _exit() | # include <unistd.h> // For fork(), exec(), and _exit() |
# include <errno.h> | # include <errno.h> |
|
# include <sys/types.h> |
|
# if defined(PEGASUS_HAS_SIGNALS) |
|
# include <sys/wait.h> |
|
# endif |
#endif | #endif |
| |
#include "OOPProviderManagerRouter.h" | #include "OOPProviderManagerRouter.h" |
|
|
*/ | */ |
AutoPtr<AnonymousPipe> _pipeToAgent; | AutoPtr<AnonymousPipe> _pipeToAgent; |
| |
|
#if defined(PEGASUS_HAS_SIGNALS) |
|
/** |
|
Process ID of the active Provider Agent. |
|
*/ |
|
pid_t _pid; |
|
#endif |
|
|
/** | /** |
The _outstandingRequestTable holds an entry for each request that has | The _outstandingRequestTable holds an entry for each request that has |
been sent to this Provider Agent for which no response has been | been sent to this Provider Agent for which no response has been |
|
|
// Ensure the destructor does not throw an exception | // Ensure the destructor does not throw an exception |
try | try |
{ | { |
|
if (isInitialized()) |
|
{ |
// Stop the responseProcessor thread by closing its connection | // Stop the responseProcessor thread by closing its connection |
_pipeFromAgent->closeReadHandle(); | _pipeFromAgent->closeReadHandle(); |
| |
|
|
pegasus_yield(); | pegasus_yield(); |
} | } |
} | } |
|
} |
catch (...) | catch (...) |
{ | { |
} | } |
|
|
PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, | PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, |
"ProviderAgentContainer::_startAgentProcess"); | "ProviderAgentContainer::_startAgentProcess"); |
| |
|
// |
|
// Serialize the starting of agent processes. If two agent processes are |
|
// started at the same time, they may get copies of each other's pipe |
|
// descriptors. If this happens, the cimserver will not get a pipe read |
|
// error when one of the agent processes exits, because the pipe will |
|
// still be writable by the other process. This locking control needs to |
|
// cover the period from where the pipes are created to where the agent |
|
// ends of the pipes are closed by the cimserver. |
|
// |
|
static Mutex agentStartupMutex; |
|
AutoMutex lock(agentStartupMutex); |
|
|
AutoPtr<AnonymousPipe> pipeFromAgent(new AnonymousPipe()); | AutoPtr<AnonymousPipe> pipeFromAgent(new AnonymousPipe()); |
AutoPtr<AnonymousPipe> pipeToAgent(new AnonymousPipe()); | AutoPtr<AnonymousPipe> pipeToAgent(new AnonymousPipe()); |
| |
|
|
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
} | } |
|
#elif defined (PEGASUS_OS_OS400) |
|
|
|
//Out of provider support for OS400 goes here when needed. |
|
|
#else | #else |
pid_t pid = fork(); | pid_t pid = fork(); |
if (pid < 0) | if (pid < 0) |
|
|
_exit(1); | _exit(1); |
} | } |
} | } |
|
# if defined(PEGASUS_HAS_SIGNALS) |
|
_pid = pid; |
|
# endif |
#endif | #endif |
| |
// | // |
|
|
{ | { |
_startAgentProcess(); | _startAgentProcess(); |
| |
_sendInitializationData(); |
|
|
|
_isInitialized = true; | _isInitialized = true; |
| |
|
_sendInitializationData(); |
|
|
// Start a thread to read and process responses from the Provider Agent | // Start a thread to read and process responses from the Provider Agent |
while (!MessageQueueService::get_thread_pool()->allocate_and_awaken( |
ThreadStatus rtn = PEGASUS_THREAD_OK; |
this, _responseProcessor)) |
while ((rtn = MessageQueueService::get_thread_pool()-> |
|
allocate_and_awaken(this, _responseProcessor)) != |
|
PEGASUS_THREAD_OK) |
|
{ |
|
if (rtn == PEGASUS_THREAD_INSUFFICIENT_RESOURCES) |
{ | { |
pegasus_yield(); | pegasus_yield(); |
} | } |
|
else |
|
{ |
|
Logger::put( |
|
Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE, |
|
"Not enough threads to process responses from the " |
|
"provider agent."); |
|
|
|
Tracer::trace(TRC_PROVIDERMANAGER, Tracer::LEVEL2, |
|
"Could not allocate thread to process responses from the " |
|
"provider agent."); |
|
|
|
throw Exception(MessageLoaderParms( |
|
"ProviderManager.OOPProviderManagerRouter." |
|
"CIMPROVAGT_THREAD_ALLOCATION_FAILED", |
|
"Failed to allocate thread for cimprovagt \"$0\".", |
|
_moduleName)); |
|
} |
|
} |
} | } |
catch (...) | catch (...) |
{ | { |
_isInitialized = false; |
// Closing the connection causes the agent process to exit |
_pipeToAgent.reset(); | _pipeToAgent.reset(); |
_pipeFromAgent.reset(); | _pipeFromAgent.reset(); |
| |
|
#if defined(PEGASUS_HAS_SIGNALS) |
|
if (_isInitialized) |
|
{ |
|
// Harvest the status of the agent process to prevent a zombie |
|
Boolean keepWaiting = false; |
|
do |
|
{ |
|
pid_t status = waitpid(_pid, 0, 0); |
|
if (status == -1) |
|
{ |
|
if (errno == EINTR) |
|
{ |
|
keepWaiting = true; |
|
} |
|
else |
|
{ |
|
Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
|
"ProviderAgentContainer::_initialize(): " |
|
"waitpid failed; errno = %d.", errno); |
|
} |
|
} |
|
} while (keepWaiting); |
|
} |
|
#endif |
|
|
|
_isInitialized = false; |
|
|
{ | { |
AutoMutex lock(_numProviderProcessesMutex); | AutoMutex lock(_numProviderProcessesMutex); |
_numProviderProcesses--; | _numProviderProcesses--; |
|
|
_numProviderProcesses--; | _numProviderProcesses--; |
} | } |
| |
|
#if defined(PEGASUS_HAS_SIGNALS) |
|
// Harvest the status of the agent process to prevent a zombie |
|
Boolean keepWaiting = false; |
|
do |
|
{ |
|
pid_t status = waitpid(_pid, 0, 0); |
|
if (status == -1) |
|
{ |
|
if (errno == EINTR) |
|
{ |
|
keepWaiting = true; |
|
} |
|
else |
|
{ |
|
Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
|
"ProviderAgentContainer::_uninitialize(): " |
|
"waitpid failed; errno = %d.", errno); |
|
} |
|
} |
|
} while (keepWaiting); |
|
#endif |
|
|
_isInitialized = false; | _isInitialized = false; |
| |
// | // |