21#include "RConfigure.h"
30#include "Xrd/XrdScheduler.hh"
31#include "XrdOuc/XrdOucStream.hh"
44 const char *incdir,
const char *libdir,
const char *datadir,
69 auto setDir = [&](XrdOucString &
target,
const char *
src,
const char *subdir) ->
bool {
77 if (!setDir(
fIncDir, incdir,
"/include"))
79 if (!setDir(
fLibDir, libdir,
"/lib"))
81 if (!setDir(
fBinDir, bindir,
"/bin"))
85 if (!setDir(
fEtcDir, etcdir,
"/etc"))
90 TRACE(XERR,
"unable to extract ROOT version information from path "<<
fIncDir);
118 if (dir && strlen(dir) > 0) {
121 if (stat(dir, &st) == -1) {
122 TRACE(XERR,
"unable to stat path "<<dir);
126 if (!S_ISDIR(st.st_mode)) {
127 TRACE(XERR,
"path "<<dir<<
" is not a directory");
133 TRACE(XERR,
"path is undefined");
147 XrdOucString vs(
" ");
149 fExport.replace(vs,XrdOucString(
""));
164 XPDLOC(SMGR,
"ParseROOTVersionInfo")
168 TRACE(XERR,
"incomplete info found: version code missing or bad: " <<
fVersionCode);
175 TRACE(XERR,
"incomplete info found: release tag missing or bad: " <<
fRelease);
179 std::ifstream gitinfo(
fEtcDir +
"/gitinfo.txt");
187 TRACE(XERR,
"incomplete info found: not a ROOT release and no " <<
fEtcDir +
"/gitinfo.txt");
191 std::string gitcommit;
192 std::getline(gitinfo, gitcommit);
193 std::getline(gitinfo, gitcommit);
219 return ((maj << 16) + (min << 8) + patch);
228 int &maj,
int &min,
int &patch)
230 if (!release || strlen(release) <= 0)
return -1;
232 XrdOucString rel(release, 7), tkn;
234 if ((from = rel.tokenize(tkn, from,
'.')) == -1)
return -1;
235 maj = atoi(tkn.c_str());
236 if ((from = rel.tokenize(tkn, from,
'/')) == -1)
return -1;
237 min = atoi(tkn.c_str());
238 if ((from = rel.tokenize(tkn, from,
' ')) == -1)
return -1;
239 patch = atoi(tkn.c_str());
267 XPDLOC(SMGR,
"ROOTMgr::SetLogDir")
269 if (
fMgr && dir && strlen(dir)) {
275 XPDERR(
"unable to assert the rootsys log validation path: "<<
fLogDir);
289 XPDLOC(SMGR,
"ROOTMgr::Config")
293 TRACE(XERR,
"problems parsing file ");
298 msg = (rcf) ?
"re-configuring" :
"configuring";
304 std::list<XrdROOT *>::iterator tri;
305 if (
fROOT.size() > 0) {
306 for (tri =
fROOT.begin(); tri !=
fROOT.end();) {
307 if ((*tri)->IsParked()) {
309 tri =
fROOT.erase(tri);
317 if (
fROOT.size() <= 0) {
318 XrdOucString dir, bd, ed, ld,
id, dd;
320 if (getenv(
"ROOTIGNOREPREFIX"))
322 dir = getenv(
"ROOTSYS");
334 if (dir.length() > 0) {
336 bd.c_str(),
id.c_str(), ld.c_str(), dd.c_str(), ed.c_str());
339 fROOT.push_back(rootc);
342 XPDFORM(mnp,
"ROOT version details: git: '%s', code: %d, {mnp} = {%d,%d,%d}",
347 XPDFORM(msg,
"ROOT dist: '%s' could not be validated", rootc->
Export());
351 if (
fROOT.size() <= 0) {
352 TRACE(XERR,
"no ROOT dir defined; ROOTSYS location missing - unloading");
374 char *val, XrdOucStream *cfg,
bool rcf)
376 XPDLOC(SMGR,
"ROOTMgr::DoDirective")
382 if (
d->fName ==
"rootsys") {
385 TRACE(XERR,
"unknown directive: "<<
d->fName);
394 XPDLOC(SMGR,
"ROOTMgr::DoDirectiveRootSys")
401 XrdOucString dir = val;
402 val = cfg->GetWord();
403 XrdOucString tag = val;
415 if (tag.length() > 0) {
416 while ((val = cfg->GetWord())) {
a[i++] = val; }
419 a[1].c_str(),
a[2].c_str(),
a[3].c_str());
421 std::list<XrdROOT *>::iterator ori;
422 for (ori =
fROOT.begin(); ori !=
fROOT.end(); ++ori) {
423 if ((*ori)->Match(rootc->
Dir(), rootc->
Tag())) {
424 if ((*ori)->IsParked()) {
434 TRACE(REQ,
"validation OK for: "<<rootc->
Export());
436 XPDFORM(mnp,
"version details: git: '%s', code: %d, {mnp} = {%d,%d,%d}",
441 fROOT.push_back(rootc);
443 TRACE(XERR,
"could not validate "<<rootc->
Export());
458 XPDLOC(SMGR,
"ROOTMgr::Validate")
460 TRACE(REQ,
"forking test and protocol retrieval");
462 if (
r->IsInvalid()) {
464 TRACE(XERR,
"invalid instance - cannot be validated");
469 if (!
r->PrgmSrv() || strlen(
r->PrgmSrv()) <= 0) {
470 TRACE(XERR,
"path to PROOF server application undefined - exit");
476 TRACE(XERR,
"scheduler undefined - exit");
483 TRACE(XERR,
"PROOT protocol number communication");
492 XrdOucString logfile, rootrc;
494 XrdOucString tag(
r->Tag());
495 tag.replace(
"/",
"-");
498 XPDFORM(rootrc,
"%s/root.%s.rootrc",
fLogDir.c_str(), tag.c_str());
503 TRACE(FORK,
"XrdROOTMgr::Validate: forking external proofsrv");
505 if (!(pid = sched->Fork(
"proofsrv"))) {
507 if (logfile.length() > 0 &&
fLogger) {
509 fLogger->Bind(logfile.c_str());
511 size_t len = strlen(
"ROOTPROOFLOGFILE=") + logfile.length() + 2;
512 char *ev =
new char[
len];
513 snprintf(ev,
len,
"ROOTPROOFLOGFILE=%s", logfile.c_str());
515 if (debug && rootrc.length() > 0) {
517 FILE *frc = fopen(rootrc.c_str(),
"w");
519 fprintf(frc,
"Proof.DebugLevel: 1\n");
523 len = strlen(
"ROOTRCFILE=") + rootrc.length() + 2;
525 snprintf(ev,
len,
"ROOTRCFILE=%s", rootrc.c_str());
530 char *argvv[6] = {0};
533 argvv[0] = (
char *)
r->PrgmSrv();
534 argvv[1] = (
char *)
"proofserv";
535 argvv[2] = (
char *)
"xpd";
536 argvv[3] = (
char *)
"test";
538 argvv[4] = (
char *)
"1";
547 TRACE(XERR,
" SetProofServEnv did not return OK - EXIT");
552 char *ev =
new char[25];
553 snprintf(ev, 25,
"ROOTOPENSOCK=%d", fp[1]);
561 TRACE(XERR,
"could not get info for user-id: "<<geteuid());
567 TRACE(XERR,
"can't acquire "<<ui.
fUser <<
" identity");
574 execv(
r->PrgmSrv(), argvv);
577 TRACE(XERR,
"returned from execv: bad, bad sign !!!");
583 TRACE(XERR,
"forking failed - exit");
590 TRACE(FORK,
"test server launched: wait for protocol ");
596 fds_r.events = POLLIN;
601 while (pollRet == 0 && ntry--) {
602 while ((pollRet = poll(&fds_r, 1, 2000)) < 0 &&
603 (errno == EINTR)) { }
605 TRACE(DBG,
"receiving PROOF server protocol number: waiting 2 s ...");
609 TRACE(XERR,
"problems receiving PROOF server protocol number");
614 TRACE(XERR,
"timed-out receiving PROOF server protocol number");
616 TRACE(XERR,
"failed to receive PROOF server protocol number");
622 r->SetValid((kXR_int16) ntohl(
proto));
625 if (logfile.length() > 0 && !debug) {
626 if (unlink(logfile.c_str()) != 0) {
627 TRACE(XERR,
"problems unlinking "<<logfile<<
"; errno: "<<errno);
630 if (debug && rootrc.length() > 0 && unlink(rootrc.c_str()) != 0) {
631 TRACE(XERR,
"problems unlinking "<<rootrc<<
"; errno: "<<errno);
651 std::list<XrdROOT *>::iterator ip;
652 for (ip =
fROOT.begin(); ip !=
fROOT.end(); ++ip) {
658 out += (*ip)->Export();
674 std::list<XrdROOT *>::iterator ip;
675 for (ip =
fROOT.begin(); ip !=
fROOT.end(); ++ip) {
676 if ((*ip)->MatchTag(tag)) {
#define ROOT_VERSION_PATCH
#define ROOT_VERSION_MAJOR
#define ROOT_VERSION_CODE
#define ROOT_VERSION_MINOR
#define TRACE(Flag, Args)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
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...
int CheckDir(const char *dir)
Check if 'dir' exists Return 0 on succes, -1 on failure.
XrdROOT(const char *dir, const char *tag, const char *bindir=0, const char *incdir=0, const char *libdir=0, const char *datadir=0, const char *etcdir=0)
Constructor: validates 'dir', gets the version and defines the tag.
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)