21#include "RConfigure.h"
29#include "Xrd/XrdScheduler.hh"
30#include "XrdOuc/XrdOucStream.hh"
41 const char *incdir,
const char *libdir,
const char *datadir)
55 if (!dir || strlen(dir) <= 0)
57 if (tag && strlen(tag) > 0) {
68 if (!incdir || strlen(incdir) <= 0) {
76 TRACE(XERR,
"unable to extract ROOT version information from path "<<
fIncDir);
85 if (!libdir || strlen(libdir) <= 0) {
93 if (!bindir || strlen(bindir) <= 0) {
101 if (!datadir || strlen(datadir) <= 0) {
127 if (dir && strlen(dir) > 0) {
130 if (stat(dir, &st) == -1) {
131 TRACE(XERR,
"unable to stat path "<<dir);
135 if (!S_ISDIR(st.st_mode)) {
136 TRACE(XERR,
"path "<<dir<<
" is not a directory");
142 TRACE(XERR,
"path is undefined");
156 XrdOucString vs(
" ");
158 fExport.replace(vs,XrdOucString(
""));
173 XPDLOC(SMGR,
"ParseROOTVersionInfo")
177 XrdOucString versfile =
fIncDir;
178 versfile +=
"/RVersion.h";
181 FILE *fv = fopen(versfile.c_str(),
"r");
183 TRACE(XERR,
"unable to open "<<versfile);
197 XrdOucString tkn, sline;
199 while (fgets(
line,
sizeof(
line), fv)) {
200 if (
fRelease.length() <= 0 && (pv = (
char *) strstr(
line,
"ROOT_RELEASE"))) {
203 pv += strlen(
"ROOT_RELEASE") + 1;
206 }
else if (
fGitCommit.length() <= 0 && (pv = (
char *) strstr(
line,
"ROOT_GIT_COMMIT"))) {
209 pv += strlen(
"ROOT_GIT_COMMIT") + 1;
212 }
else if ((pv = (
char *) strstr(
line,
"ROOT_VERSION_CODE"))) {
214 pv += strlen(
"ROOT_VERSION_CODE");
215 while (pv[0] ==
' ') pv++;
225 TRACE(XERR,
"incomplete info found in "<<versfile<<
": version code missing or bad: "<<
fVersionCode);
232 TRACE(XERR,
"incomplete info found in "<<versfile<<
": release tag missing or bad: "<<
fRelease);
239 XrdOucString gitcommit =
fIncDir;
240 gitcommit +=
"/RGitCommit.h";
243 if ((fv = fopen(gitcommit.c_str(),
"r"))) {
247 while (fgets(
line,
sizeof(
line), fv)) {
248 if (
fGitCommit.length() <= 0 && (pv = (
char *) strstr(
line,
"ROOT_GIT_COMMIT"))) {
251 pv += strlen(
"ROOT_GIT_COMMIT") + 1;
262 TRACE(REQ,
"file "<<gitcommit<<
" not found");
288 return ((maj << 16) + (min << 8) + patch);
297 int &maj,
int &min,
int &patch)
299 if (!release || strlen(release) <= 0)
return -1;
301 XrdOucString rel(release, 7), tkn;
303 if ((from = rel.tokenize(tkn, from,
'.')) == -1)
return -1;
304 maj = atoi(tkn.c_str());
305 if ((from = rel.tokenize(tkn, from,
'/')) == -1)
return -1;
306 min = atoi(tkn.c_str());
307 if ((from = rel.tokenize(tkn, from,
' ')) == -1)
return -1;
308 patch = atoi(tkn.c_str());
336 XPDLOC(SMGR,
"ROOTMgr::SetLogDir")
338 if (
fMgr && dir && strlen(dir)) {
344 XPDERR(
"unable to assert the rootsys log validation path: "<<
fLogDir);
358 XPDLOC(SMGR,
"ROOTMgr::Config")
362 TRACE(XERR,
"problems parsing file ");
367 msg = (rcf) ?
"re-configuring" :
"configuring";
373 std::list<XrdROOT *>::iterator tri;
374 if (
fROOT.size() > 0) {
375 for (tri =
fROOT.begin(); tri !=
fROOT.end();) {
376 if ((*tri)->IsParked()) {
378 tri =
fROOT.erase(tri);
386 if (
fROOT.size() <= 0) {
387 XrdOucString dir, bd, ld,
id, dd;
389 if (getenv(
"ROOTIGNOREPREFIX"))
391 dir = getenv(
"ROOTSYS");
402 if (dir.length() > 0) {
404 bd.c_str(),
id.c_str(), ld.c_str(), dd.c_str());
407 fROOT.push_back(rootc);
410 XPDFORM(mnp,
"ROOT version details: git: '%s', code: %d, {mnp} = {%d,%d,%d}",
415 XPDFORM(msg,
"ROOT dist: '%s' could not be validated", rootc->
Export());
419 if (
fROOT.size() <= 0) {
420 TRACE(XERR,
"no ROOT dir defined; ROOTSYS location missing - unloading");
442 char *val, XrdOucStream *cfg,
bool rcf)
444 XPDLOC(SMGR,
"ROOTMgr::DoDirective")
450 if (
d->fName ==
"rootsys") {
453 TRACE(XERR,
"unknown directive: "<<
d->fName);
462 XPDLOC(SMGR,
"ROOTMgr::DoDirectiveRootSys")
469 XrdOucString dir = val;
470 val = cfg->GetWord();
471 XrdOucString tag = val;
483 if (tag.length() > 0) {
484 while ((val = cfg->GetWord())) {
a[i++] = val; }
487 a[1].c_str(),
a[2].c_str(),
a[3].c_str());
489 std::list<XrdROOT *>::iterator ori;
490 for (ori =
fROOT.begin(); ori !=
fROOT.end(); ++ori) {
491 if ((*ori)->Match(rootc->
Dir(), rootc->
Tag())) {
492 if ((*ori)->IsParked()) {
502 TRACE(REQ,
"validation OK for: "<<rootc->
Export());
504 XPDFORM(mnp,
"version details: git: '%s', code: %d, {mnp} = {%d,%d,%d}",
509 fROOT.push_back(rootc);
511 TRACE(XERR,
"could not validate "<<rootc->
Export());
526 XPDLOC(SMGR,
"ROOTMgr::Validate")
528 TRACE(REQ,
"forking test and protocol retrieval");
530 if (
r->IsInvalid()) {
532 TRACE(XERR,
"invalid instance - cannot be validated");
537 if (!
r->PrgmSrv() || strlen(
r->PrgmSrv()) <= 0) {
538 TRACE(XERR,
"path to PROOF server application undefined - exit");
544 TRACE(XERR,
"scheduler undefined - exit");
551 TRACE(XERR,
"PROOT protocol number communication");
560 XrdOucString logfile, rootrc;
562 XrdOucString tag(
r->Tag());
563 tag.replace(
"/",
"-");
566 XPDFORM(rootrc,
"%s/root.%s.rootrc",
fLogDir.c_str(), tag.c_str());
571 TRACE(FORK,
"XrdROOTMgr::Validate: forking external proofsrv");
573 if (!(pid = sched->Fork(
"proofsrv"))) {
575 if (logfile.length() > 0 &&
fLogger) {
577 fLogger->Bind(logfile.c_str());
579 size_t len = strlen(
"ROOTPROOFLOGFILE=") + logfile.length() + 2;
580 char *ev =
new char[len];
581 snprintf(ev, len,
"ROOTPROOFLOGFILE=%s", logfile.c_str());
583 if (debug && rootrc.length() > 0) {
585 FILE *frc = fopen(rootrc.c_str(),
"w");
587 fprintf(frc,
"Proof.DebugLevel: 1\n");
591 len = strlen(
"ROOTRCFILE=") + rootrc.length() + 2;
593 snprintf(ev, len,
"ROOTRCFILE=%s", rootrc.c_str());
598 char *argvv[6] = {0};
601 argvv[0] = (
char *)
r->PrgmSrv();
602 argvv[1] = (
char *)
"proofserv";
603 argvv[2] = (
char *)
"xpd";
604 argvv[3] = (
char *)
"test";
606 argvv[4] = (
char *)
"1";
615 TRACE(XERR,
" SetProofServEnv did not return OK - EXIT");
620 char *ev =
new char[25];
621 snprintf(ev, 25,
"ROOTOPENSOCK=%d", fp[1]);
629 TRACE(XERR,
"could not get info for user-id: "<<geteuid());
635 TRACE(XERR,
"can't acquire "<<ui.
fUser <<
" identity");
642 execv(
r->PrgmSrv(), argvv);
645 TRACE(XERR,
"returned from execv: bad, bad sign !!!");
651 TRACE(XERR,
"forking failed - exit");
658 TRACE(FORK,
"test server launched: wait for protocol ");
664 fds_r.events = POLLIN;
669 while (pollRet == 0 && ntry--) {
670 while ((pollRet = poll(&fds_r, 1, 2000)) < 0 &&
671 (errno == EINTR)) { }
673 TRACE(DBG,
"receiving PROOF server protocol number: waiting 2 s ...");
677 TRACE(XERR,
"problems receiving PROOF server protocol number");
682 TRACE(XERR,
"timed-out receiving PROOF server protocol number");
684 TRACE(XERR,
"failed to receive PROOF server protocol number");
690 r->SetValid((kXR_int16) ntohl(
proto));
693 if (logfile.length() > 0 && !debug) {
694 if (unlink(logfile.c_str()) != 0) {
695 TRACE(XERR,
"problems unlinking "<<logfile<<
"; errno: "<<errno);
698 if (debug && rootrc.length() > 0 && unlink(rootrc.c_str()) != 0) {
699 TRACE(XERR,
"problems unlinking "<<rootrc<<
"; errno: "<<errno);
719 std::list<XrdROOT *>::iterator ip;
720 for (ip =
fROOT.begin(); ip !=
fROOT.end(); ++ip) {
726 out += (*ip)->Export();
742 std::list<XrdROOT *>::iterator ip;
743 for (ip =
fROOT.begin(); ip !=
fROOT.end(); ++ip) {
744 if ((*ip)->MatchTag(tag)) {
#define TRACE(Flag, Args)
int DoDirectiveClass(XrdProofdDirective *, char *val, XrdOucStream *cfg, bool rcf)
Generic class directive processor.
static int GetUserInfo(const char *usr, XrdProofUI &ui)
Get information about user 'usr' in a thread safe way.
static int AssertDir(const char *path, XrdProofUI ui, bool changeown)
Make sure that 'path' exists and is owned by the entity described by 'ui'.
static int CheckIf(XrdOucStream *s, const char *h)
Check existence and match condition of an 'if' directive If none (valid) is found,...
virtual int Config(bool rcf=0)
void Register(const char *dname, XrdProofdDirective *d)
XrdScheduler * Sched() const
const char * Host() const
const char * EffectiveUser() const
int SetProofServEnv(XrdProofdProtocol *p, void *in)
Set environment for proofserv.
int Validate(XrdROOT *r, XrdScheduler *sched)
Start a trial server application to test forking and get the version of the protocol run by the PROOF...
XrdROOT * GetVersion(const char *tag)
Return pointer to the ROOT version corresponding to 'tag' or 0 if not found.
int DoDirective(XrdProofdDirective *d, char *val, XrdOucStream *cfg, bool rcf)
Update the priorities of the active sessions.
void RegisterDirectives()
Register directives for configuration.
XrdOucString ExportVersions(XrdROOT *def)
Return a string describing the available versions, with the default version 'def' markde with a '*'.
std::list< XrdROOT * > fROOT
XrdROOTMgr(XrdProofdManager *mgr, XrdProtocol_Config *pi, XrdSysError *e)
Constructor.
int Config(bool rcf=0)
Run configuration and parse the entered config directives.
void SetLogDir(const char *d)
Set the log dir.
int DoDirectiveRootSys(char *, XrdOucStream *, bool)
Process 'rootsys' directive.
static int GetVersionCode(const char *release)
Translate 'release' into a version code integer following the rules in $ROOTSYS/include/RVersion....
const char * Export() const
static int ParseReleaseString(const char *release, int &maj, int &min, int &patch)
Extract from 'release' its major, minor and patch numerical components; 'release' must be in the form...
XrdROOT(const char *dir, const char *tag, const char *bindir=0, const char *incdir=0, const char *libdir=0, const char *datadir=0)
Constructor: validates 'dir', gets the version and defines the tag.
int CheckDir(const char *dir)
Check if 'dir' exists Return 0 on succes, -1 on failure.
int ParseROOTVersionInfo()
Extract ROOT version information associated with 'dir'.
const char * GitCommit() const
void SetValid(kXR_int16 vers=-1)
Set valid, save protocol and finalize the export string.
static int ChangePerm(uid_t uid, gid_t gid)
static constexpr double pi