version 1.12, 2007/08/10 21:30:25
|
version 1.16, 2008/02/04 12:21:58
|
|
|
#if defined(PEGASUS_OS_TYPE_WINDOWS) | #if defined(PEGASUS_OS_TYPE_WINDOWS) |
# include <windows.h> | # include <windows.h> |
#else | #else |
|
# include <spawn.h> |
# include <unistd.h> | # include <unistd.h> |
|
# include <errno.h> |
# include <sys/types.h> | # include <sys/types.h> |
# include <sys/time.h> | # include <sys/time.h> |
# include <sys/resource.h> | # include <sys/resource.h> |
|
|
switch (mode) | switch (mode) |
{ | { |
case 'r': | case 'r': |
return fopen(path, "rb"); |
return fopen(path, "r"); |
| |
case 'w': | case 'w': |
return fopen(path, "wb"); |
return fopen(path, "w"); |
| |
case 'a': | case 'a': |
return fopen(path, "a+"); | return fopen(path, "a+"); |
|
|
AnonymousPipe*& readPipe, | AnonymousPipe*& readPipe, |
AnonymousPipe*& writePipe) | AnonymousPipe*& writePipe) |
{ | { |
|
PEG_METHOD_ENTER(TRC_SERVER,"ExecutorLoopbackImpl::startProviderAgent"); |
#if !defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) | #if !defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) |
| |
# if defined(PEGASUS_OS_TYPE_WINDOWS) | # if defined(PEGASUS_OS_TYPE_WINDOWS) |
|
|
&siStartInfo, // STARTUPINFO | &siStartInfo, // STARTUPINFO |
&piProcInfo)) // PROCESS_INFORMATION | &piProcInfo)) // PROCESS_INFORMATION |
{ | { |
|
PEG_METHOD_EXIT(); |
return -1; | return -1; |
} | } |
| |
|
|
readPipe = pipeFromAgent.release(); | readPipe = pipeFromAgent.release(); |
writePipe = pipeToAgent.release(); | writePipe = pipeToAgent.release(); |
| |
|
PEG_METHOD_EXIT(); |
return 0; | return 0; |
| |
# else /* POSIX CASE FOLLOWS */ | # else /* POSIX CASE FOLLOWS */ |
|
|
int to[2]; | int to[2]; |
int from[2]; | int from[2]; |
| |
|
# if defined(PEGASUS_OS_ZOS) |
|
// zOS is using __spawn2() instead of frok() |
|
struct __inheritance inherit; |
|
const char *c_argv[5]; |
|
char arg1[32]; |
|
char arg2[32]; |
|
|
|
# endif |
|
|
do | do |
{ | { |
// Resolve full path of "cimprovagt". | // Resolve full path of "cimprovagt". |
|
|
String path = FileSystem::getAbsolutePath( | String path = FileSystem::getAbsolutePath( |
pegasusHome.getCString(), PEGASUS_PROVIDER_AGENT_PROC_NAME); | pegasusHome.getCString(), PEGASUS_PROVIDER_AGENT_PROC_NAME); |
| |
# if !defined(PEGASUS_DISABLE_PROV_USERCTXT) |
# if !defined(PEGASUS_DISABLE_PROV_USERCTXT) && !defined(PEGASUS_OS_ZOS) |
| |
PEGASUS_UID_T newUid = (PEGASUS_UID_T)-1; | PEGASUS_UID_T newUid = (PEGASUS_UID_T)-1; |
PEGASUS_GID_T newGid = (PEGASUS_GID_T)-1; | PEGASUS_GID_T newGid = (PEGASUS_GID_T)-1; |
|
|
if (!System::lookupUserId( | if (!System::lookupUserId( |
userName.getCString(), newUid, newGid)) | userName.getCString(), newUid, newGid)) |
{ | { |
PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL2, |
PEG_TRACE((TRC_SERVER, Tracer::LEVEL2, |
"System::lookupUserId(%s) failed.", |
"System::lookupUserId(%s) for provider user " |
|
"context failed.", |
(const char*)userName.getCString())); | (const char*)userName.getCString())); |
|
PEG_METHOD_EXIT(); |
return -1; | return -1; |
} | } |
} | } |
|
|
// Create "to-agent" pipe: | // Create "to-agent" pipe: |
| |
if (pipe(to) != 0) | if (pipe(to) != 0) |
|
{ |
|
PEG_METHOD_EXIT(); |
return -1; | return -1; |
|
} |
|
|
| |
// Create "from-agent" pipe: | // Create "from-agent" pipe: |
| |
if (pipe(from) != 0) | if (pipe(from) != 0) |
|
{ |
|
PEG_METHOD_EXIT(); |
return -1; | return -1; |
|
} |
|
|
|
// Start provider agent: |
|
|
|
# if defined(PEGASUS_OS_ZOS) |
|
// zOS is using __spawn2() to start provider agent |
|
sprintf(arg1, "%d", to[0]); |
|
sprintf(arg2, "%d", from[1]); |
| |
// Fork process: |
CString program_name = path.getCString(); |
| |
# if defined(PEGASUS_OS_VMS) |
c_argv[0] = program_name; |
|
c_argv[1] = arg1; |
|
c_argv[2] = arg2; |
|
c_argv[3] = module; |
|
c_argv[4] = NULL; |
|
|
|
// reset the inherit structure |
|
memset(&inherit,0,sizeof(inherit)); |
|
|
|
// The provider agent should get a defined JobName. |
|
inherit.flags=SPAWN_SETJOBNAME; |
|
memcpy( inherit.jobname,"CFZOOPA ", |
|
sizeof(inherit.jobname)); |
|
|
|
CString program = path.getCString(); |
|
|
|
PEG_TRACE((TRC_SERVER, Tracer::LEVEL4, |
|
"Starting provider agent: %s %s %s %s %s", |
|
program,program_name,arg1,arg2,module)); |
|
|
|
pid = __spawn2(program,0,NULL,&inherit, |
|
c_argv,(const char **)environ); |
|
|
|
if (pid < 0) |
|
{ |
|
PEG_TRACE((TRC_SERVER, Tracer::LEVEL4, |
|
"Spawn of provider agent fails:%s " |
|
"( errno %d , reason code %08X )", |
|
strerror(errno) ,errno,__errno2())); |
|
PEG_METHOD_EXIT(); |
|
return -1; |
|
} |
|
|
|
# elif defined(PEGASUS_OS_VMS) |
pid = (int)vfork(); | pid = (int)vfork(); |
# elif defined(PEGASUS_OS_PASE) | # elif defined(PEGASUS_OS_PASE) |
pid = (int)fork400("QUMEPRVAGT",0); | pid = (int)fork400("QUMEPRVAGT",0); |
|
|
pid = (int)fork(); | pid = (int)fork(); |
# endif | # endif |
| |
|
# if !defined(PEGASUS_OS_ZOS) |
|
|
if (pid < 0) | if (pid < 0) |
|
{ |
|
PEG_TRACE((TRC_SERVER, Tracer::LEVEL4, |
|
"Fork for provider agent fails: errno = %d",errno)); |
|
PEG_METHOD_EXIT(); |
return -1; | return -1; |
|
} |
| |
// If child proceses. | // If child proceses. |
|
|
if (pid == 0) | if (pid == 0) |
{ | { |
# if !defined(PEGASUS_OS_VMS) | # if !defined(PEGASUS_OS_VMS) |
|
|
CString cstr = path.getCString(); | CString cstr = path.getCString(); |
if (execl(cstr, cstr, arg1, arg2, module, (char*)0) == -1) | if (execl(cstr, cstr, arg1, arg2, module, (char*)0) == -1) |
{ | { |
PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL2, |
PEG_TRACE((TRC_SERVER, Tracer::LEVEL2, |
"execl() failed. errno = %d.", errno)); | "execl() failed. errno = %d.", errno)); |
_exit(1); | _exit(1); |
} | } |
} | } |
} | } |
|
# else /* PEGASUS_OS_ZOS */ |
|
if (pid > 0) |
|
{ |
|
PEG_TRACE((TRC_SERVER, Tracer::LEVEL4, |
|
"Provider agent started suggessfully: Pid(%d).",pid)); |
|
break; |
|
} |
|
#endif /* PEGASUS_OS_ZOS */ |
|
|
} | } |
while (0); | while (0); |
| |
|
|
readPipe = new AnonymousPipe(readFdStr, 0); | readPipe = new AnonymousPipe(readFdStr, 0); |
writePipe = new AnonymousPipe(0, writeFdStr); | writePipe = new AnonymousPipe(0, writeFdStr); |
| |
|
PEG_METHOD_EXIT(); |
return 0; | return 0; |
| |
# endif /* POSIX CASE */ | # endif /* POSIX CASE */ |