version 1.25.2.6, 2006/09/19 18:06:47
|
version 1.25.2.8, 2006/10/10 18:10:15
|
|
|
# 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 |
|
|
} | } |
# 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 |
Boolean keepWaiting = false; |
pid_t status = 0; |
do | do |
{ | { |
pid_t status = waitpid(_pid, 0, 0); |
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 |
Boolean keepWaiting = false; |
pid_t status = 0; |
do | do |
{ | { |
pid_t status = waitpid(_pid, 0, 0); |
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; |