version 1.25.2.8, 2006/10/10 18:10:15
|
version 1.28, 2006/04/19 19:39:25
|
|
|
# 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> | # include <sys/types.h> |
# include <sys/resource.h> |
|
# if defined(PEGASUS_HAS_SIGNALS) | # if defined(PEGASUS_HAS_SIGNALS) |
# include <sys/wait.h> | # include <sys/wait.h> |
# endif | # endif |
|
|
{ | { |
public: | public: |
OutstandingRequestEntry( | OutstandingRequestEntry( |
String originalMessageId_, |
String messageId_, |
CIMRequestMessage* requestMessage_, | CIMRequestMessage* requestMessage_, |
CIMResponseMessage*& responseMessage_, | CIMResponseMessage*& responseMessage_, |
Semaphore* responseReady_) | Semaphore* responseReady_) |
: originalMessageId(originalMessageId_), |
: messageId(messageId_), |
requestMessage(requestMessage_), | requestMessage(requestMessage_), |
responseMessage(responseMessage_), | responseMessage(responseMessage_), |
responseReady(responseReady_) | responseReady(responseReady_) |
{ | { |
} | } |
| |
/** |
String messageId; |
A unique value is substituted as the request messageId attribute to |
|
allow responses to be definitively correllated with requests. |
|
The original messageId value is stored here to avoid a race condition |
|
between the processing of a response chunk and the resetting of the |
|
original messageId in the request message. |
|
*/ |
|
String originalMessageId; |
|
CIMRequestMessage* requestMessage; | CIMRequestMessage* requestMessage; |
CIMResponseMessage*& responseMessage; | CIMResponseMessage*& responseMessage; |
Semaphore* responseReady; | Semaphore* responseReady; |
|
|
ProviderAgentContainer( | ProviderAgentContainer( |
const String & moduleName, | const String & moduleName, |
const String & userName, | const String & userName, |
Uint16 userContext, |
|
PEGASUS_INDICATION_CALLBACK_T indicationCallback, | PEGASUS_INDICATION_CALLBACK_T indicationCallback, |
PEGASUS_RESPONSE_CHUNK_CALLBACK_T responseChunkCallback, | PEGASUS_RESPONSE_CHUNK_CALLBACK_T responseChunkCallback, |
PEGASUS_PROVIDERMODULEFAIL_CALLBACK_T providerModuleFailCallback, |
|
Boolean subscriptionInitComplete); | Boolean subscriptionInitComplete); |
| |
~ProviderAgentContainer(); | ~ProviderAgentContainer(); |
|
|
String _userName; | String _userName; |
| |
/** | /** |
User Context setting of the provider module served by this Provider |
|
Agent. |
|
*/ |
|
Uint16 _userContext; |
|
|
|
/** |
|
Callback function to which all generated indications are sent for | Callback function to which all generated indications are sent for |
processing. | processing. |
*/ | */ |
|
|
PEGASUS_RESPONSE_CHUNK_CALLBACK_T _responseChunkCallback; | PEGASUS_RESPONSE_CHUNK_CALLBACK_T _responseChunkCallback; |
| |
/** | /** |
Callback function to be called upon detection of failure of a |
|
provider module. |
|
*/ |
|
PEGASUS_PROVIDERMODULEFAIL_CALLBACK_T _providerModuleFailCallback; |
|
|
|
/** |
|
Indicates whether the Provider Agent is active. | Indicates whether the Provider Agent is active. |
*/ | */ |
Boolean _isInitialized; | Boolean _isInitialized; |
|
|
ProviderAgentContainer::ProviderAgentContainer( | ProviderAgentContainer::ProviderAgentContainer( |
const String & moduleName, | const String & moduleName, |
const String & userName, | const String & userName, |
Uint16 userContext, |
|
PEGASUS_INDICATION_CALLBACK_T indicationCallback, | PEGASUS_INDICATION_CALLBACK_T indicationCallback, |
PEGASUS_RESPONSE_CHUNK_CALLBACK_T responseChunkCallback, | PEGASUS_RESPONSE_CHUNK_CALLBACK_T responseChunkCallback, |
PEGASUS_PROVIDERMODULEFAIL_CALLBACK_T providerModuleFailCallback, |
|
Boolean subscriptionInitComplete) | Boolean subscriptionInitComplete) |
: _moduleName(moduleName), | : _moduleName(moduleName), |
_userName(userName), | _userName(userName), |
_userContext(userContext), |
|
_indicationCallback(indicationCallback), | _indicationCallback(indicationCallback), |
_responseChunkCallback(responseChunkCallback), | _responseChunkCallback(responseChunkCallback), |
_providerModuleFailCallback(providerModuleFailCallback), |
|
_isInitialized(false), | _isInitialized(false), |
_subscriptionInitComplete(subscriptionInitComplete) | _subscriptionInitComplete(subscriptionInitComplete) |
{ | { |
|
|
} | } |
#elif defined (PEGASUS_OS_OS400) | #elif defined (PEGASUS_OS_OS400) |
| |
//Out of process provider support for OS400 goes here when needed. |
//Out of provider support for OS400 goes here when needed. |
| |
#else | #else |
| |
|
|
} | } |
# endif | # endif |
| |
// Close all file descriptors except stdin/stdout/stderr |
|
// and the pipe handles needed by the Provider Agent process. |
|
|
|
Uint32 readFd = atoi(readHandle); |
|
Uint32 writeFd = atoi(writeHandle); |
|
struct rlimit fileLimit; |
|
|
|
if (getrlimit(RLIMIT_NOFILE, &fileLimit) == 0) |
|
{ |
|
Uint32 maxFd = (Uint32)fileLimit.rlim_cur; |
|
for (Uint32 i = 3; i < maxFd - 1; i++) |
|
{ |
|
if ((i != readFd) && (i != writeFd)) |
|
{ |
|
close(i); |
|
} |
|
} |
|
} |
|
|
|
execl(agentCommandPathCString, agentCommandPathCString, | execl(agentCommandPathCString, agentCommandPathCString, |
readHandle, writeHandle, | readHandle, writeHandle, |
(const char*)_moduleName.getCString(), (char*)0); | (const char*)_moduleName.getCString(), (char*)0); |
|
|
if (_isInitialized) | if (_isInitialized) |
{ | { |
// Harvest the status of the agent process to prevent a zombie | // Harvest the status of the agent process to prevent a zombie |
pid_t status = 0; |
Boolean keepWaiting = false; |
do | do |
{ | { |
status = waitpid(_pid, 0, 0); |
pid_t status = waitpid(_pid, 0, 0); |
} while ((status == -1) && (errno == EINTR)); |
|
|
|
if (status == -1) | if (status == -1) |
{ | { |
|
if (errno == EINTR) |
|
{ |
|
keepWaiting = true; |
|
} |
|
else |
|
{ |
Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, | Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
"ProviderAgentContainer::_initialize(): " | "ProviderAgentContainer::_initialize(): " |
"waitpid failed; errno = %d.", errno); | "waitpid failed; errno = %d.", errno); |
} | } |
} | } |
|
} while (keepWaiting); |
|
} |
#endif | #endif |
| |
_isInitialized = false; | _isInitialized = false; |
|
|
| |
#if defined(PEGASUS_HAS_SIGNALS) | #if defined(PEGASUS_HAS_SIGNALS) |
// Harvest the status of the agent process to prevent a zombie | // Harvest the status of the agent process to prevent a zombie |
pid_t status = 0; |
Boolean keepWaiting = false; |
do | do |
{ | { |
status = waitpid(_pid, 0, 0); |
pid_t status = waitpid(_pid, 0, 0); |
} while ((status == -1) && (errno == EINTR)); |
|
|
|
if (status == -1) | if (status == -1) |
{ | { |
|
if (errno == EINTR) |
|
{ |
|
keepWaiting = true; |
|
} |
|
else |
|
{ |
Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, | Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2, |
"ProviderAgentContainer::_uninitialize(): " | "ProviderAgentContainer::_uninitialize(): " |
"waitpid failed; errno = %d.", errno); | "waitpid failed; errno = %d.", errno); |
} | } |
|
} |
|
} while (keepWaiting); |
#endif | #endif |
| |
_isInitialized = false; | _isInitialized = false; |
|
|
// connection | // connection |
// | // |
{ | { |
|
// |
|
// If not a clean shutdown, log a warning message in case module |
|
// included indication providers |
|
// |
|
if (!cleanShutdown) |
|
{ |
|
Logger::put_l( |
|
Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING, |
|
"ProviderManager.OOPProviderManagerRouter." |
|
"OOP_PROVIDER_MODULE_FAILURE_DETECTED", |
|
"A failure was detected in provider module $0. The" |
|
" generation of indications by providers in this module" |
|
" may be affected. To ensure these providers are" |
|
" serving active subscriptions, disable and then" |
|
" re-enable this module using the cimprovider command.", |
|
_moduleName); |
|
} |
|
|
AutoMutex tableLock(_outstandingRequestTableMutex); | AutoMutex tableLock(_outstandingRequestTableMutex); |
| |
CIMResponseMessage* response = | CIMResponseMessage* response = |
|
|
i != 0; i++) | i != 0; i++) |
{ | { |
PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2, | PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL2, |
String("Completing messageId \"") + i.key() + |
String("Completing messageId \"") + i.value()->messageId + |
"\" with a null response."); | "\" with a null response."); |
i.value()->responseMessage = response; | i.value()->responseMessage = response; |
i.value()->responseReady->signal(); | i.value()->responseReady->signal(); |
} | } |
| |
_outstandingRequestTable.clear(); | _outstandingRequestTable.clear(); |
|
|
// |
|
// If not a clean shutdown, call the provider module failure |
|
// callback |
|
// |
|
if (!cleanShutdown) |
|
{ |
|
// |
|
// Call the provider module failure callback to |
|
// communicate the failure to the Provider Manager Service |
|
// Provider Manager Service will inform Indication Service |
|
// |
|
_providerModuleFailCallback (_moduleName, _userName, |
|
_userContext); |
|
} |
|
} | } |
} | } |
catch (...) | catch (...) |
|
|
} | } |
} while (response == _REQUEST_NOT_PROCESSED); | } while (response == _REQUEST_NOT_PROCESSED); |
| |
if (request->getType() == CIM_SUBSCRIPTION_INIT_COMPLETE_REQUEST_MESSAGE) |
|
{ |
|
_subscriptionInitComplete = true; |
|
} |
|
|
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return response; | return response; |
} | } |
|
|
// | // |
Semaphore waitSemaphore(0); | Semaphore waitSemaphore(0); |
OutstandingRequestEntry outstandingRequestEntry( | OutstandingRequestEntry outstandingRequestEntry( |
originalMessageId, request, response, &waitSemaphore); |
uniqueMessageId, request, response, &waitSemaphore); |
| |
// | // |
// Lock the Provider Agent Container while initializing the | // Lock the Provider Agent Container while initializing the |
|
|
| |
// Put the original message ID into the response | // Put the original message ID into the response |
response->messageId = | response->messageId = |
_outstandingRequestEntry->originalMessageId; |
_outstandingRequestEntry->requestMessage->messageId; |
| |
// Call the response chunk callback to process the chunk | // Call the response chunk callback to process the chunk |
_responseChunkCallback( | _responseChunkCallback( |
|
|
| |
OOPProviderManagerRouter::OOPProviderManagerRouter( | OOPProviderManagerRouter::OOPProviderManagerRouter( |
PEGASUS_INDICATION_CALLBACK_T indicationCallback, | PEGASUS_INDICATION_CALLBACK_T indicationCallback, |
PEGASUS_RESPONSE_CHUNK_CALLBACK_T responseChunkCallback, |
PEGASUS_RESPONSE_CHUNK_CALLBACK_T responseChunkCallback) |
PEGASUS_PROVIDERMODULEFAIL_CALLBACK_T providerModuleFailCallback) |
|
{ | { |
PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, | PEG_METHOD_ENTER(TRC_PROVIDERMANAGER, |
"OOPProviderManagerRouter::OOPProviderManagerRouter"); | "OOPProviderManagerRouter::OOPProviderManagerRouter"); |
| |
_indicationCallback = indicationCallback; | _indicationCallback = indicationCallback; |
_responseChunkCallback = responseChunkCallback; | _responseChunkCallback = responseChunkCallback; |
_providerModuleFailCallback = providerModuleFailCallback; |
|
_subscriptionInitComplete = false; | _subscriptionInitComplete = false; |
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
|
|
} | } |
else | else |
{ | { |
// |
|
// Look up the Provider Agent for this module instance and requesting |
|
// user |
|
// |
|
ProviderAgentContainer* pa = _lookupProviderAgent(providerModule, |
|
request); |
|
PEGASUS_ASSERT(pa != 0); |
|
|
|
// |
|
// Forward the request to the provider agent |
|
// |
|
response.reset(pa->processMessage(request)); |
|
} |
|
|
|
response->syncAttributes(request); |
|
|
|
PEG_METHOD_EXIT(); |
|
return response.release(); |
|
} |
|
|
|
ProviderAgentContainer* OOPProviderManagerRouter::_lookupProviderAgent( |
|
const CIMInstance& providerModule, |
|
CIMRequestMessage* request) |
|
{ |
|
// Retrieve the provider module name | // Retrieve the provider module name |
String moduleName; | String moduleName; |
CIMValue nameValue = providerModule.getProperty( | CIMValue nameValue = providerModule.getProperty( |
|
|
| |
if (userContext == 0) | if (userContext == 0) |
{ | { |
userContext = PEGASUS_DEFAULT_PROV_USERCTXT; |
userContext = PG_PROVMODULE_USERCTXT_PRIVILEGED; |
} | } |
| |
String userName; | String userName; |
|
|
} | } |
else if (userContext == PG_PROVMODULE_USERCTXT_DESIGNATED) | else if (userContext == PG_PROVMODULE_USERCTXT_DESIGNATED) |
{ | { |
// Retrieve the provider module designated user property value |
// Retrieve the provider module name |
providerModule.getProperty(providerModule.findProperty( | providerModule.getProperty(providerModule.findProperty( |
PEGASUS_PROPERTYNAME_MODULE_DESIGNATEDUSER)).getValue(). | PEGASUS_PROPERTYNAME_MODULE_DESIGNATEDUSER)).getValue(). |
get(userName); | get(userName); |
|
|
PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4, | PEG_TRACE_STRING(TRC_PROVIDERMANAGER, Tracer::LEVEL4, |
"User name = " + userName); | "User name = " + userName); |
| |
|
// Look up the Provider Agent for this module and user |
|
ProviderAgentContainer* pa = _lookupProviderAgent(moduleName, userName); |
|
PEGASUS_ASSERT(pa != 0); |
|
|
|
// |
|
// Forward the request to the provider agent |
|
// |
|
response.reset(pa->processMessage(request)); |
|
} |
|
|
|
response->syncAttributes(request); |
|
|
|
PEG_METHOD_EXIT(); |
|
return response.release(); |
|
} |
|
|
|
ProviderAgentContainer* OOPProviderManagerRouter::_lookupProviderAgent( |
|
const String& moduleName, |
|
const String& userName) |
|
{ |
ProviderAgentContainer* pa = 0; | ProviderAgentContainer* pa = 0; |
String key = moduleName + ":" + userName; | String key = moduleName + ":" + userName; |
| |
|
|
if (!_providerAgentTable.lookup(key, pa)) | if (!_providerAgentTable.lookup(key, pa)) |
{ | { |
pa = new ProviderAgentContainer( | pa = new ProviderAgentContainer( |
moduleName, userName, userContext, |
moduleName, userName, _indicationCallback, _responseChunkCallback, |
_indicationCallback, _responseChunkCallback, |
|
_providerModuleFailCallback, |
|
_subscriptionInitComplete); | _subscriptionInitComplete); |
_providerAgentTable.insert(key, pa); | _providerAgentTable.insert(key, pa); |
} | } |