Loading...
Searching...
No Matches
XrdOucProg Class Reference

`#include <XrdOucProg.hh>`

Collaboration diagram for XrdOucProg:

## Public Member Functions

| XrdOucProg (XrdSysError *errobj=0, int efd=-1)
| ~XrdOucProg ()
int | Feed (const char *data)
int | Feed (const char *data, int dlen)
int | Feed (const char *data[], const int dlen[])
XrdOucStream * | getStream () const
bool | isLocal ()
int | Run (char *outBuff, int outBsz, const char *arg1=0, const char *arg2=0, const char *arg3=0, const char *arg4=0) const
int | Run (const char *arg1=0, const char *arg2=0, const char *arg3=0, const char *arg4=0) const
int | Run (const char *argV[], int argC, const char *envV[]=0) const
int | Run (XrdOucStream *Sp, const char *arg1=0, const char *arg2=0, const char *arg3=0, const char *arg4=0) const
int | Run (XrdOucStream *Sp, const char *argV[], int argc=0, const char *envV[]=0) const
int | RunDone (XrdOucStream &cmd) const
int | Setup (const char *prog, XrdSysError *errP=0, int(*Proc)(XrdOucStream *, char **, int)=0)
int | Start (void)

## Detailed Description

Definition at line 37 of file XrdOucProg.hh.

## Constructor & Destructor Documentation

## XrdOucProg()

XrdOucProg::XrdOucProg | ( | XrdSysError * | errobj = 0,
|  | int | efd = -1 )

inline

Definition at line 45 of file XrdOucProg.hh.

: eDest(errobj), myStream(0), myProc(0), ArgBuff(0),
Arg(&ArgBuff), numArgs(0), theEFD(efd) {}
eDest
static XrdSysError eDest(0,"crypto_")

## ~XrdOucProg()

XrdOucProg::~XrdOucProg | ( |  | ) |

Definition at line 53 of file XrdOucProg.cc.

{
Reset();
if (myStream) delete myStream;
}

## Member Function Documentation

## Feed() [1/3]

int XrdOucProg::Feed | ( | const char * | data | ) |

inline

Definition at line 63 of file XrdOucProg.hh.

{return Feed(data, (int)strlen(data));}
XrdOucProg::Feed
int Feed(const char *data[], const int dlen[])
Definition XrdOucProg.cc:63

References Feed().

Referenced by Feed().

Here is the call graph for this function:
Here is the caller graph for this function:

## Feed() [2/3]

int XrdOucProg::Feed | ( | const char * | data,
|  | int | dlen )

inline

Definition at line 57 of file XrdOucProg.hh.

{const char *myData[2] = {data, 0};
const int myDlen[2] = {dlen, 0};
return Feed(myData, myDlen);
}

References Feed().

Here is the call graph for this function:

## Feed() [3/3]

int XrdOucProg::Feed | ( | const char * | data[],
|  | const int | dlen[] )

Definition at line 63 of file XrdOucProg.cc.

{
static XrdSysMutex feedMutex;
XrdSysMutexHelper feedHelper;
int rc;
// Make sure we have a stream
//
if (!myStream) return EPIPE;
feedHelper.Lock(&feedMutex);
// Check if this command is still running
//
if (!myStream->isAlive() && !Restart())
{if (eDest) eDest->Emsg("Prog" "Unable to restart", Arg[0]);
return EPIPE;
}
// Send the line to the program
//
if (!myStream->Put((const char **)data, (const int *)dlen)) return 0;
if (eDest)
eDest->Emsg("Prog", myStream->LastError(), "feed", Arg[0]);
if ((rc = Restart()))
{if (eDest) eDest->Emsg("Prog", rc, "restart", Arg[0]);
return EPIPE;
}
if (!myStream->Put((const char **)data, (const int *)dlen)) return 0;
if (eDest)
eDest->Emsg("Prog", myStream->LastError(), "refeed", Arg[0]);
return EPIPE;
}
XrdSysMutexHelper::Lock
void Lock(XrdSysMutex *Mutex)
Definition XrdSysPthread.hh:266

References XrdSysMutexHelper::Lock().

Referenced by Feed().

Here is the call graph for this function:
Here is the caller graph for this function:

## getStream()

XrdOucStream * XrdOucProg::getStream | ( |  | ) | const

inline

Definition at line 68 of file XrdOucProg.hh.

{return myStream;}

## isLocal()

bool XrdOucProg::isLocal | ( |  | ) |

inline

Definition at line 72 of file XrdOucProg.hh.

{return myProc != 0;}

## Run() [1/5]

int XrdOucProg::Run | ( | char * | outBuff,
|  | int | outBsz,
|  | const char * | arg1 = 0,
|  | const char * | arg2 = 0,
|  | const char * | arg3 = 0,
|  | const char * | arg4 = 0 ) const

Definition at line 216 of file XrdOucProg.cc.

{
XrdOucStream cmd;
char *lp, *tp;
int n, rc;
// Execute the command
//
runWithVec(&cmd, rc);
if (rc) return rc;
// Drain the first line to the output buffer
//
if (outBuff && outBsz > 0)
{if ((lp = cmd.GetLine()))
{while (*lp && *lp == ' ') lp++;
if ((n = strlen(lp)))
{tp = lp+n-1;
while(*tp-- == ' ') n--;
if (n >= outBsz) n = outBsz-1;
strncpy(outBuff, lp, n); outBuff += n;
}
}
*outBuff = 0;
}
// Drain remaining output
//
while((lp = cmd.GetLine())) {}
// All done
//
return RunDone(cmd);
}
runWithVec
#define runWithVec(strmP, theRC)
Definition XrdOucProg.cc:100
XrdOucProg::RunDone
int RunDone(XrdOucStream &cmd) const
Definition XrdOucProg.cc:257
XrdOucStream::GetLine
char * GetLine()
Definition XrdOucStream.cc:554

References XrdOucStream::GetLine(), RunDone(), and runWithVec.

Here is the call graph for this function:

## Run() [2/5]

int XrdOucProg::Run | ( | const char * | arg1 = 0,
|  | const char * | arg2 = 0,
|  | const char * | arg3 = 0,
|  | const char * | arg4 = 0 ) const

Definition at line 192 of file XrdOucProg.cc.

{
XrdOucStream cmd;
char *lp;
int rc;
// Execute the command
//
runWithVec(&cmd, rc);
if (rc) return rc;
// Drain all output
//
while((lp = cmd.GetLine()))
if (eDest && *lp) eDest->Emsg("Run", lp);
// All done
//
return RunDone(cmd);
}

References XrdOucStream::GetLine(), RunDone(), and runWithVec.

Here is the call graph for this function:

## Run() [3/5]

int XrdOucProg::Run | ( | const char * | argV[],
|  | int | argC,
|  | const char * | envV[] = 0 ) const

Definition at line 156 of file XrdOucProg.cc.

{
XrdOucStream cmd;
char *lp;
int rc;
// Execute the command
//
rc = Run(&cmd, argV, argC, envV);
if (rc) return rc;
// Drain all output
//
while((lp = cmd.GetLine()))
if (eDest && *lp) eDest->Emsg("Run", lp);
// All done
//
return RunDone(cmd);
}
XrdOucProg::Run
int Run(XrdOucStream *Sp, const char *argV[], int argc=0, const char *envV[]=0) const
Definition XrdOucProg.cc:108

References XrdOucStream::GetLine(), Run(), and RunDone().

Here is the call graph for this function:

## Run() [4/5]

int XrdOucProg::Run | ( | XrdOucStream * | Sp,
|  | const char * | arg1 = 0,
|  | const char * | arg2 = 0,
|  | const char * | arg3 = 0,
|  | const char * | arg4 = 0 ) const

Definition at line 179 of file XrdOucProg.cc.

{
int rc;
// Execute the command
//
runWithVec(Sp, rc);
return rc;
}

References runWithVec.

## Run() [5/5]

int XrdOucProg::Run | ( | XrdOucStream * | Sp,
|  | const char * | argV[],
|  | int | argc = 0,
|  | const char * | envV[] = 0 ) const

Definition at line 108 of file XrdOucProg.cc.

{
char **myArgs;
int rc, totArgs = numArgs + argC;
// If we have no program, return an error
//
if (!ArgBuff)
{if (eDest) eDest->Emsg("Run", "No program specified");
return -ENOEXEC;
}
// Copy arguments to stack storage (we could avoid this but not with the stack).
//
myArgs = (char**)alloca(sizeof(char *) * (totArgs + 1));
if (numArgs) memcpy(myArgs, Arg, sizeof(char*)*numArgs);
if (argC) memcpy(&myArgs[numArgs], argV, sizeof(char*)*argC);
myArgs[totArgs] = 0;
// If this is a local process then just execute it inline on this thread
//
if (myProc) return (*myProc)(Sp, myArgs, totArgs);
// Execute the command, possibly setting an environment.
//
if (envV)
{XrdOucEnv progEnv, *oldEnv = Sp->SetEnv(&progEnv);
progEnv.PutPtr("XrdEnvars**", (void *)envV);
rc = Sp->Exec(myArgs, 1, theEFD);
Sp->SetEnv(oldEnv);
} else rc = Sp->Exec(myArgs, 1, theEFD);
// Diagnose any errors
//
if (rc)
{rc = Sp->LastError();
if (eDest) eDest->Emsg("Run", rc, "execute", Arg[0]);
return -rc;
}
// All done, caller will drain output
//
return 0;
}
XrdOucEnv::PutPtr
void PutPtr(const char *varname, void *value)
Definition XrdOucEnv.cc:298
XrdOucStream::SetEnv
XrdOucEnv * SetEnv(XrdOucEnv *newEnv)
Definition XrdOucStream.hh:191
XrdOucStream::LastError
int LastError()
Definition XrdOucStream.hh:163
XrdOucStream::Exec
int Exec(const char *, int inrd=0, int efd=0)
Definition XrdOucStream.cc:419

References XrdOucStream::Exec(), XrdOucStream::LastError(), XrdOucEnv::PutPtr(), and XrdOucStream::SetEnv().

Referenced by Run(), and Start().

Here is the call graph for this function:
Here is the caller graph for this function:

## RunDone()

int XrdOucProg::RunDone | ( | XrdOucStream & | cmd | ) | const

Definition at line 257 of file XrdOucProg.cc.

{
int rc;
// If this is an inline program then just return 0. There is no external process
// and the return code was returned at the time the inline process was run.
//
if (myProc) return 0;
// Drain the command
//
rc = cmd.Drain();
// Determine ending status
//
if (WIFSIGNALED(rc))
{if (eDest)
{char buff[16];
sprintf(buff, "%d", WTERMSIG(rc));
eDest->Emsg("Run", Arg[0], "killed by signal", buff);
}
return -EPIPE;
}
if (WIFEXITED(rc))
{rc = WEXITSTATUS(rc);
if (rc && eDest)
{char buff[16];
sprintf(buff, "%d", rc);
eDest->Emsg("Run", Arg[0], "ended with status", buff);
}
return -rc;
}
return 0; // We'll assume all went well here
}
XrdOucStream::Drain
int Drain()
Definition XrdOucStream.cc:367

References XrdOucStream::Drain().

Referenced by Run(), Run(), and Run().

Here is the call graph for this function:
Here is the caller graph for this function:

## Setup()

int XrdOucProg::Setup | ( | const char * | prog,
|  | XrdSysError * | errP = 0,
|  | int(* | Proc )(XrdOucStream *, char **, int) = 0 )

Definition at line 296 of file XrdOucProg.cc.

{
static const int maxArgs = 65;
char *argV[maxArgs];
int rc;
// Prepare to handle the program
//
Reset();
if (!errP) errP = eDest;
myProc = 0;
ArgBuff = strdup(prog);
// Construct the argv array based on passed command line.
//
rc = XrdOucUtils::argList(ArgBuff, argV, maxArgs);
if (rc <= 0)
{if (errP)
{if (!rc || !argV[0])
{const char *pgm = (Proc ? "procedure" : "program");
errP->Emsg("Run", pgm, "name not specified.");
} else errP->Emsg("Run", rc, "set up", argV[0]);
}
return (rc ? rc : -EINVAL);
}
// Record the arguments including the phamtom null pointer. We must have
// atleast one, the program or procedure name.
//
numArgs = rc;
Arg = new char*[rc+1];
memcpy(Arg, argV, sizeof(char *) * (rc+1));
// If this is a local process then just record its address
//
if ((myProc = Proc)) return 0;
// Make sure the program is really executable
//
if (access(Arg[0], X_OK))
{rc = errno;
if (errP) errP->Emsg("Run", rc, "set up", Arg[0]);
Reset();
return rc;
}
return 0;
}
access
#define access(a, b)
Definition XrdPosix.hh:44
XrdOucUtils::argList
static int argList(char *args, char **argV, int argC)
Definition XrdOucUtils.cc:125
XrdSysError::Emsg
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition XrdSysError.cc:95

References access, XrdOucUtils::argList(), and XrdSysError::Emsg().

Here is the call graph for this function:

## Start()

int XrdOucProg::Start | ( | void |  | ) |

Definition at line 349 of file XrdOucProg.cc.

{
// Create a stream for this command (it is an eror if we are already started)
//
if (myStream) return EBUSY;
if (!(myStream = new XrdOucStream(eDest))) return ENOMEM;
// Execute the command and let it linger
//
theEFD = 0;
return Run(myStream);
}

References Run().

Here is the call graph for this function:

The documentation for this class was generated from the following files:

- XrdOucProg.hh
- XrdOucProg.cc