35 #include <sys/types.h>
57 const char *Pgm =
"cconfig: ";
67 int inList(
const char *var,
const char **Vec)
70 while(Vec[i] && strcmp(Vec[i],var)) i++;
83 int mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
84 int fd =
open(outFN, O_CREAT | O_TRUNC | O_WRONLY, mode);
109 std::cerr <<
"Usage: cconfig -c <cfn> [<opts>] [<args>]\n"
110 "<opts>: [-h <host>] [-n <name>] [-o <file>] [-x <prog>]\n"
111 "<args>: [[pfx]*]<directive> | <directive>[*[sfx]] [<args>]"
120 int main(
int argc,
char *argv[])
130 const char *Cfn = 0, *Host = 0, *Name = 0, *Xeq =
"xrootd", *oFile=0;
131 const char *noSub[] = {
"cms.prepmsg",
"ofs.notifymsg",
"oss.stagemsg",
132 "frm.xfr.copycmd", 0};
133 const char *ifChk[] = {
"xrd.port",
"all.role",
"all.manager", 0};
134 const char *slChk[] = {
"frm.xfr.copycmd", 0};
136 char buff[4096], *var, c;
137 int i, retc = 0, cfgFD, chkQ = 0;
142 if (argc > 1 &&
'-' == *argv[1])
143 while ((c = getopt(argc,argv,
":c:h:n:o:x:")) && ((
unsigned char)c != 0xff))
146 case 'c': Cfn = optarg;
148 case 'h': Host= optarg;
150 case 'n': Name= optarg;
152 case 'o': oFile=optarg;
154 case 'x': Xeq = optarg;
156 default: sprintf(buff,
"'%c'",
optopt);
157 if (c ==
':')
Say.
Say(Pgm, buff,
" value not specified.");
158 else Say.
Say(Pgm, buff,
" option is invalid.");
165 if (!Cfn) {
Say.
Say(Pgm,
"Config file not specified.");
Usage(1);}
169 if (!Host) Host = theAddr.
Name();
170 else if (!theAddr.
Set(Host,0)) Host = theAddr.
Name();
171 if (!Host) {
Say.
Say(Pgm,
"Unable to determine host name."); exit(3);}
176 chkQ = (DirQ.
First() != 0);
180 if ( (cfgFD =
open(Cfn, O_RDONLY, 0)) < 0)
188 sprintf(buff,
"%s %s@%s", Xeq, Name, Host);
195 Config->Capture(&theConfig);
199 while((var =
Config->GetMyFirstWord()))
200 {
if (chkQ && !DirQ.
Find(var)) {
Config->noEcho();
continue;}
203 while((var =
Config->GetWord()) && *var !=
'/') {}
204 oldEnv =
Config->SetEnv(0);
205 if (var)
Config->GetRest(buff,
sizeof(buff));
208 else if (
inList(var, ifChk))
209 {
while((var =
Config->GetWord()) && strcmp(var,
"if")) {}
212 {
Config->noEcho();
continue;}
214 else Config->GetRest(buff,
sizeof(buff));
220 if ((retc =
Config->LastError()))
221 {
Say.
Say(Pgm,
XrdSysE2T(retc),
" reading config file ", Cfn); retc = 8;}
226 if (oFile && !retc) retc =
cfOut(oFile, theConfig);
int main(int argc, char *argv[])
int inList(const char *var, const char **Vec)
int cfOut(const char *outFN, XrdOucString &cFile)
int open(const char *path, int oflag,...)
ssize_t write(int fildes, const void *buf, size_t nbyte)
const char * XrdSysE2T(int errcode)
const char * Name(const char *eName=0, const char **eText=0)
const char * Set(const char *hSpec, int pNum=PortInSpec)
XrdOucNList * Find(const char *name)
void Replace(const char *name, int nval)
const char * c_str() const
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)
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)