Skip to content

Commit

Permalink
Write on a '.env' file to record execution environment. This is to
Browse files Browse the repository at this point in the history
allow automatic collection of debugging information.
  • Loading branch information
abh3 committed Jun 17, 2013
1 parent cfe6e30 commit acc9b27
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/Xrd/XrdConfig.cc
Expand Up @@ -445,6 +445,10 @@ int XrdConfig::Configure(int argc, char **argv)
}
#endif

// Establish a pid/manifest file for auto-collection
//
if (!NoGo) Manifest(pidFN);

// All done, close the stream and return the return code.
//
temp = (NoGo ? " initialization failed." : " initialization completed.");
Expand Down Expand Up @@ -620,6 +624,60 @@ int XrdConfig::getUG(char *parm, uid_t &newUid, gid_t &newGid)
return 1;
}

/******************************************************************************/
/* M a n i f e s t */
/******************************************************************************/

void XrdConfig::Manifest(const char *pidfn)
{
const char *Slash;
char envBuff[8192], pwdBuff[1024], manBuff[1024], *pidP;
int envFD, envLen;

// Get the current working directory
//
if (!getcwd(pwdBuff, sizeof(pwdBuff)))
{Log.Emsg("Config", "Unable to get current working directory!");
return;
}

// Create environment string
//
envLen = snprintf(envBuff, sizeof(envBuff), "pid=%d&host=%s&inst=%s&ver=%s"
"&cfgfn=%s&cwd=%s&apath=%s&logfn=%s\n",
static_cast<int>(getpid()), ProtInfo.myName,
ProtInfo.myInst, XrdVSTRING,
(ProtInfo.ConfigFN ? ProtInfo.ConfigFN : ""), pwdBuff,
ProtInfo.AdmPath, Log.logger()->xlogFN());

// Find out where we should write this
//
if (pidfn && (Slash = rindex(pidfn, '/')))
{strncpy(manBuff, pidfn, Slash-pidfn); pidP = manBuff+(Slash-pidfn);}
else {strcpy(manBuff, "/tmp"); pidP = manBuff+4;}

// Construct the pid file name for ourselves
//
snprintf(pidP, sizeof(manBuff)-(pidP-manBuff), "/%s.%s.env",
ProtInfo.myProg, ProtInfo.myInst);

// Open the file
//
if ((envFD = open(manBuff, O_WRONLY|O_CREAT|O_TRUNC, 0664)) < 0)
{Log.Emsg("Config", errno, "create envfile", manBuff);
return;
}

// Write out environmental information
//
if (write(envFD, envBuff, envLen) < 0)
Log.Emsg("Config", errno, "write to envfile", manBuff);

// All done
//
close(envFD);
}

/******************************************************************************/
/* s e t F D L */
/******************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions src/Xrd/XrdConfig.hh
Expand Up @@ -65,6 +65,7 @@ private:
int ASocket(const char *path, const char *fname, mode_t mode);
int ConfigProc(void);
int getUG(char *parm, uid_t &theUid, gid_t &theGid);
void Manifest(const char *pidfn);
int setFDL();
int Setup(char *dfltp);
void Usage(int rc);
Expand Down
4 changes: 4 additions & 0 deletions src/XrdSys/XrdSysLogger.hh
Expand Up @@ -90,6 +90,10 @@ char traceEnd() {Logger_Mutex.UnLock(); return '\n';}
//
int xlogFD();

// xlogFN() return the filename of the log file or "stderr"
//
const char *xlogFN() {return (ePath ? ePath : "stderr");}

private:

XrdSysMutex Logger_Mutex;
Expand Down

0 comments on commit acc9b27

Please sign in to comment.