34 #include <sys/param.h>
35 #include <sys/types.h>
68 #define TS_Xeq(x,m) if (!strcmp(x,var)) return m(Config);
79 while((tp = tpp)) {tpp = tp->
next;
delete tp;}
81 while((tp = tpp)) {tpp = tp->
next;
delete tp;}
83 if (VNID_Lib) free(VNID_Lib);
84 if (VNID_Parms) free(VNID_Parms);
85 if (prfLib) free(prfLib);
86 if (prfParms) free(prfParms);
105 const char *eText = 0;
106 char buff[256], *slash, *temp, *bP, sfx;
110 myHost = getenv(
"XRDHOST");
111 if (!myHost) myHost =
"localhost";
113 CMSPath = getenv(
"XRDADMINPATH");
114 if (CMSPath && *CMSPath) CMSPath = strdup(CMSPath);
116 isMeta = (How & configMeta) != 0;
117 isMan = (What& configMan) != 0;
118 isServer = What == configServer;
122 if (!(NoGo = ConfigProc(cfn)) && isMan)
123 {
if (How & configProxy) eText = (PanList ? 0 :
"Proxy manager");
125 eText = (How & configMeta ?
"Meta manager" :
"Manager");
126 if (eText) {
Say.
Emsg(
"Config", eText,
"not specified."); NoGo=1;}
136 free(CMSPath); CMSPath = temp;
142 if (What & configServer) sfx =
's';
143 else if (What & configSuper) sfx =
'u';
148 if (How & configProxy)
151 }
else tpl = ManList;
155 if (!ConfigSID(cfn, tpl, sfx)) NoGo = 1;
161 while(tpe) {i += strlen(tpe->
text) + 9; tpe = tpe->
next;}
162 bP = temp = (
char *)malloc(i);
164 {bP += sprintf(bP,
"%s:%d ", tpl->
text, tpl->val);
174 if (What & configSuper)
175 {
while((tpl = ManList)) {ManList = tpl->
next;
delete tpl;}
176 slash = (CMSPath[i-1] ==
'/' ? (
char *)
"" : (
char *)
"/");
177 sprintf(buff,
"%s%solbd.super", CMSPath, slash);
179 SMode = SModeP = FailOver;
184 temp = (What & (configMan|configSuper) ? (
char *)
"nimda" : (
char *)
"admin");
185 slash = (CMSPath[i-1] ==
'/' ? (
char *)
"" : (
char *)
"/");
186 sprintf(buff,
"%s%solbd.%s", CMSPath, slash, temp);
187 free(CMSPath); CMSPath = strdup(buff);
189 RepWaitMS = RepWait * 1000;
194 {
Say.
Emsg(
"Config", ENOMEM,
"allocate initial msg objects");
200 if (prfLib && cmsMon)
202 if (!perfMon || !perfMon->Configure(cfn, prfParms, *
Say.
logger(),
204 {
Say.
Emsg(
"Config",
"Unable to configure performance monitor plugin.");
219 int XrdCmsClientConfig::ConfigProc(
const char *ConfigFN)
221 static int DoneOnce = 0;
223 int cfgFD, retc, NoGo = 0;
230 if (!ConfigFN || !*ConfigFN)
231 {
Say.
Emsg(
"Config",
"cms configuration file not specified.");
237 if ( (cfgFD =
open(ConfigFN, O_RDONLY, 0)) < 0)
238 {
Say.
Emsg(
"Config", errno,
"open config file", ConfigFN);
242 static const char *cvec[] = {
"*** cms plugin config:", 0 };
247 while((var =
Config.GetMyFirstWord()))
248 {
if (!strncmp(var,
"cms.", 4)
249 || !strncmp(var,
"odc.", 4)
250 || !strcmp(var,
"all.manager")
251 || !strcmp(var,
"all.adminpath")
252 || !strcmp(var,
"olb.adminpath"))
253 if (ConfigXeq(var+4,
Config)) {
Config.Echo(); NoGo = 1;}
258 if ((retc =
Config.LastError()))
259 NoGo =
Say.
Emsg(
"Config", retc,
"read config file", ConfigFN);
272 bool XrdCmsClientConfig::ConfigSID(
const char *cFN,
XrdOucTList *tpl,
char sfx)
280 if (!myVNID)
return false;
286 if (!sidVal || *sidVal ==
'!')
288 if (!sidVal) msg =
"too many managers.";
290 Say.
Emsg(
"Config ",
"Unable to generate system ID; ", msg);
294 Say.
Say(
"Config ",
"Global System Identification: ", sidVal);
307 TS_Xeq(
"adminpath", xapath);
342 if (!pval || !pval[0])
343 {
Say.
Emsg(
"Config",
"cms admin path not specified");
return 1;}
348 {
Say.
Emsg(
"Config",
"cms admin path not absolute");
return 1;}
352 if (CMSPath) free(CMSPath);
376 if (!(val =
Config.GetWord()) || !val[0])
377 {
Say.
Emsg(
"Config",
"tag not specified");
return 1;}
381 if ((
int)strlen(val) > 16)
382 {
Say.
Emsg(
"Config",
"tag is > 16 characters");
return 1;}
386 if (cidTag) free(cidTag);
387 cidTag = strdup(val);
411 if (!(val =
Config.GetWord()))
412 {
Say.
Emsg(
"Config",
"conwait value not specified.");
return 1;}
459 StorageHelper(
char **v1,
char **v2) : val1(v1), val2(v2) {}
460 ~StorageHelper() {
if (*val1) free(*val1);
461 if (*val2) free(*val2);
467 char *val, *hSpec = 0, *hPort = 0;
468 StorageHelper SHelp(&hSpec, &hPort);
469 int rc, xMeta = 0, xProxy = 0, smode = FailOver;
473 if ((val =
Config.GetWord()))
474 {
if (!strcmp(
"peer", val))
return Config.noEcho();
475 if ((xProxy = !strcmp(
"proxy", val))) val =
Config.GetWord();
476 else if ((xMeta = !strcmp(
"meta", val)))
477 if (isMeta || isMan) val =
Config.GetWord();
478 else return Config.noEcho();
479 else if (isMeta)
return Config.noEcho();
485 {
if (!strcmp(
"any", val)) smode = FailOver;
486 else if (!strcmp(
"all", val)) smode = RoundRob;
489 {
if (xProxy) SModeP = smode;
498 {
Say.
Emsg(
"Config",
"manager host name not specified");
return 1;}
499 else hSpec = strdup(val);
507 if ((val =
Config.GetWord()) && !strcmp(
"if", val))
509 myHost, myName, getenv(
"XRDPROG"))) <= 0)
510 {
if (!rc)
Config.noEcho();
return (rc < 0);}
514 if (xMeta && !isMeta) {haveMeta = 1;
return 0;}
515 theList = (xProxy ? &PanList : &ManList);
548 if (!isServer)
return Config.noEcho();
550 if (!(val =
Config.GetWord()))
551 {
Say.
Emsg(
"Config",
"perf options not specified");
return 1;}
553 if (strcmp(
"xrootd", val))
return Config.noEcho();
556 do {
if (!strcmp(
"int", val))
557 {
if (!(val =
Config.GetWord()))
558 {
Say.
Emsg(
"Config",
"perf int value not specified");
563 else if (!strcmp(
"lib", val))
565 prfLib, &prfParms) ? 0 : 1);
568 else if (!strcmp(
"pgm", val))
569 {
Say.
Emsg(
"Config",
"perf pgm is not supported for xrootd.");
572 else Say.
Say(
"Config warning: ignoring invalid perf option '",val,
"'.");
573 }
while((val =
Config.GetWord()));
603 static struct reqsopts {
const char *opname;
int istime;
int *oploc;}
606 {
"delay", 1, &RepDelay},
607 {
"fwd", 0, &FwdWait},
608 {
"noresp", 0, &RepNone},
609 {
"prep", 0, &PrepWait},
610 {
"repwait", 1, &RepWait}
612 int i, ppp, numopts =
sizeof(rqopts)/
sizeof(
struct reqsopts);
614 if (!(val =
Config.GetWord()))
615 {
Say.
Emsg(
"Config",
"request arguments not specified");
return 1;}
618 do {
for (i = 0; i < numopts; i++)
619 if (!strcmp(val, rqopts[i].opname))
620 {
if (!(val =
Config.GetWord()))
621 {
Say.
Emsg(
"Config",
"request argument value not specified");
623 if (rqopts[i].istime ?
627 else *rqopts[i].oploc = ppp;
630 if (i >= numopts)
Say.
Say(
"Config warning: ignoring invalid request option '",val,
"'.");
631 }
while((val =
Config.GetWord()));
652 static struct traceopts {
const char *opname;
int opval;} tropts[] =
662 int i, neg, trval = 0, numopts =
sizeof(tropts)/
sizeof(
struct traceopts);
664 if (!(val =
Config.GetWord()))
665 {
Say.
Emsg(
"config",
"trace option not specified");
return 1;}
667 {
if (!strcmp(val,
"off")) trval = 0;
668 else {
if ((neg = (val[0] ==
'-' && val[1]))) val++;
669 for (i = 0; i < numopts; i++)
670 {
if (!strcmp(val, tropts[i].opname))
671 {
if (neg) trval &= ~tropts[i].opval;
672 else trval |= tropts[i].opval;
677 Say.
Say(
"Config warning: ignoring invalid trace option '",val,
"'.");
703 char *val, parms[1024];
707 if (!(val =
Config.GetWord()) || !val[0])
708 {
Say.
Emsg(
"Config",
"vnid not specified");
return 1;}
712 if (VNID_Lib) free(VNID_Lib);
713 VNID_Lib = strdup(val);
717 if (VNID_Parms) {free(VNID_Parms); VNID_Parms = 0;}
718 if (*VNID_Lib ==
'@')
719 {
if (!
Config.GetRest(parms,
sizeof(parms)))
720 {
Say.
Emsg(
"Config",
"vnid plug-in parameters too long");
return 1;}
721 if (*parms) VNID_Parms = strdup(parms);
int open(const char *path, int oflag,...)
int Configure(const char *cfn, configWhat What, configHow How)
static char * getVnId(XrdSysError &eDest, const char *cfgFN, const char *nidlib, const char *nidparm, char nidType)
static char * setSystemID(XrdOucTList *tp, const char *iVNID, const char *iTag, char iType)
static XrdCmsPerfMon * loadPerfMon(XrdSysError *eDest, const char *libPath, XrdVersionInfo &urVer)
Load the performance monitor plugin.
static char * ParseManPort(XrdSysError *eDest, XrdOucStream &CFile, char *hSpec)
static bool ParseMan(XrdSysError *eDest, XrdOucTList **oldMans, char *hSpec, char *hPort, int *sPort=0, bool hush=false)
static int Export(const char *Var, const char *Val)
static char * genPath(const char *path, const char *inst, const char *psfx=0)
static bool parseLib(XrdSysError &eDest, XrdOucStream &Config, const char *libName, char *&path, char **libparm)
static const char * InstName(int TranOpt=0)
static int doIf(XrdSysError *eDest, XrdOucStream &Config, const char *what, const char *hname, const char *nname, const char *pname)
static int a2i(XrdSysError &, const char *emsg, const char *item, int *val, int minv=-1, int maxv=-1)
static int a2tm(XrdSysError &, const char *emsg, const char *item, int *val, int minv=-1, int maxv=-1)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
XrdSysLogger * logger(XrdSysLogger *lp=0)