diff --git a/src/Xrd/XrdConfig.cc b/src/Xrd/XrdConfig.cc index 2ce97441b14..936c905de06 100644 --- a/src/Xrd/XrdConfig.cc +++ b/src/Xrd/XrdConfig.cc @@ -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."); @@ -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(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 */ /******************************************************************************/ diff --git a/src/Xrd/XrdConfig.hh b/src/Xrd/XrdConfig.hh index 73ccf57098f..9cbcdeb146f 100644 --- a/src/Xrd/XrdConfig.hh +++ b/src/Xrd/XrdConfig.hh @@ -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); diff --git a/src/XrdSys/XrdSysLogger.hh b/src/XrdSys/XrdSysLogger.hh index 5c08c30c852..61300a2ac43 100644 --- a/src/XrdSys/XrdSysLogger.hh +++ b/src/XrdSys/XrdSysLogger.hh @@ -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;