#include <fcntl.h>
#include <cstdio>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include "XrdNet/XrdNetAddr.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdOuc/XrdOucNList.hh"
#include "XrdOuc/XrdOucStream.hh"
#include "XrdOuc/XrdOucString.hh"
#include "XrdOuc/XrdOucUtils.hh"
#include "XrdSys/XrdSysE2T.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdSys/XrdSysLogger.hh"
#include "XrdSys/XrdSysHeaders.hh"
#include "XrdSys/XrdSysPthread.hh"
Go to the source code of this file.
◆ cfOut()
Definition at line 78 of file XrdAppsCconfig.cc.
83 int mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
84 int fd =
open(outFN, O_CREAT | O_TRUNC | O_WRONLY, mode);
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 * c_str() const
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)
References XrdOucString::c_str(), close, XrdOucString::length(), open(), XrdCms::Say, XrdSysError::Say(), write(), and XrdSysE2T().
Referenced by main().
◆ inList()
int inList |
( |
const char * |
var, |
|
|
const char ** |
Vec |
|
) |
| |
◆ main()
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Definition at line 120 of file XrdAppsCconfig.cc.
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 inList(const char *var, const char **Vec)
int cfOut(const char *outFN, XrdOucString &cFile)
XrdOucNList * Find(const char *name)
void Replace(const char *name, int nval)
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)
References cfOut(), XrdCms::Config, XrdOucUtils::doIf(), XrdOucNList_Anchor::Find(), XrdOucNList_Anchor::First(), inList(), XrdOucUtils::InstName(), XrdNetAddrInfo::Name(), open(), optind, optopt, XrdOucNList_Anchor::Replace(), XrdCms::Say, XrdSysError::Say(), XrdNetAddr::Set(), Usage(), and XrdSysE2T().
◆ Usage()
Definition at line 107 of file XrdAppsCconfig.cc.
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>]"
Referenced by main().