XRootD
Loading...
Searching...
No Matches
XrdAppsCconfig.cc File Reference
#include <fcntl.h>
#include <cstdio>
#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/XrdOucUtils.hh"
#include "XrdSys/XrdSysE2T.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdSys/XrdSysLogger.hh"
#include "XrdSys/XrdSysHeaders.hh"
#include "XrdSys/XrdSysPthread.hh"
+ Include dependency graph for XrdAppsCconfig.cc:

Go to the source code of this file.

Functions

int inList (const char *var, const char **Vec)
 
int main (int argc, char *argv[])
 
void Usage (int rc)
 

Function Documentation

◆ inList()

int inList ( const char *  var,
const char **  Vec 
)

Definition at line 53 of file XrdAppsCconfig.cc.

54{
55 int i = 0;
56 while(Vec[i] && strcmp(Vec[i],var)) i++;
57 return (Vec[i] != 0);
58}

Referenced by XrdCpConfig::Config(), and main().

+ Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 75 of file XrdAppsCconfig.cc.

76{
77 static const char *Pgm = "cconfig: ";
78 extern char *optarg;
79 extern int opterr, optind, optopt;
80
82 XrdSysError Say(&Logger, "cconfig");
84 XrdOucEnv myEnv, *oldEnv = 0;
86 XrdNetAddr theAddr(0);
87
88 const char *Cfn = 0, *Host = 0, *Name = 0, *Xeq = "xrootd";
89 const char *noSub[] = {"cms.prepmsg", "ofs.notifymsg", "oss.stagemsg",
90 "frm.xfr.copycmd", 0};
91 const char *ifChk[] = {"xrd.port", "all.role", "all.manager", 0};
92 const char *slChk[] = {"frm.xfr.copycmd", 0};
93
94 char buff[4096], *var, c;
95 int i, retc = 0, cfgFD, chkQ = 0;
96
97// Process the options
98//
99 opterr = 0;
100 if (argc > 1 && '-' == *argv[1])
101 while ((c = getopt(argc,argv,":c:h:n:x:")) && ((unsigned char)c != 0xff))
102 { switch(c)
103 {
104 case 'c': Cfn = optarg;
105 break;
106 case 'h': Host= optarg;
107 break;
108 case 'n': Name= optarg;
109 break;
110 case 'x': Xeq = optarg;
111 break;
112 default: sprintf(buff,"'%c'", optopt);
113 if (c == ':') Say.Say(Pgm, buff, " value not specified.");
114 else Say.Say(Pgm, buff, " option is invalid.");
115 Usage(1);
116 }
117 }
118
119// Make sure config file has been specified
120//
121 if (!Cfn) {Say.Say(Pgm, "Config file not specified."); Usage(1);}
122
123// Get full host name
124//
125 if (!Host) Host = theAddr.Name();
126 else if (!theAddr.Set(Host,0)) Host = theAddr.Name();
127 if (!Host) {Say.Say(Pgm, "Unable to determine host name."); exit(3);}
128
129// Prepare all selector arguments
130//
131 for (i = optind; i < argc; i++) DirQ.Replace(argv[i],0);
132 chkQ = (DirQ.First() != 0);
133
134// Open the config file
135//
136 if ( (cfgFD = open(Cfn, O_RDONLY, 0)) < 0)
137 {Say.Say(Pgm, XrdSysE2T(errno), " opening config file ", Cfn);
138 exit(4);
139 }
140
141// Construct instance name and stream
142//
143 Name = XrdOucUtils::InstName(Name);
144 sprintf(buff,"%s %s@%s", Xeq, Name, Host);
145 Config = new XrdOucStream(&Say, strdup(buff), &myEnv, "");
146 Config->Attach(cfgFD);
147
148// Now start reading records until eof.
149//
150 while((var = Config->GetMyFirstWord()))
151 {if (chkQ && !DirQ.Find(var)) {Config->noEcho(); continue;}
152 if (inList(var, noSub))
153 {if (inList(var, slChk))
154 while((var = Config->GetWord()) && *var != '/') {}
155 oldEnv = Config->SetEnv(0);
156 if (var) Config->GetRest(buff, sizeof(buff));
157 Config->SetEnv(oldEnv);
158 }
159 else if (inList(var, ifChk))
160 {while((var = Config->GetWord()) && strcmp(var, "if")) {}
161 if (var && !XrdOucUtils::doIf(&Say, *Config, "directive",
162 Host, Name, Xeq))
163 {Config->noEcho(); continue;}
164 }
165 else Config->GetRest(buff, sizeof(buff));
166 Config->Echo();
167 }
168
169// Now check if any errors occurred during file i/o
170//
171 if ((retc = Config->LastError()))
172 {Say.Say(Pgm, XrdSysE2T(retc), " reading config file ", Cfn); retc = 8;}
173 Config->Close();
174
175// Should never get here
176//
177 exit(retc);
178}
int inList(const char *var, const char **Vec)
void Usage(int rc)
XrdOucPup XrdCmsParser::Pup & Say
static XrdSysLogger Logger
int optopt
int optind
#define open
Definition XrdPosix.hh:71
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:99
XrdOucNList * First()
void Replace(const char *name, int nval)
XrdOucNList * Find(const char *name)
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)
XrdCmsConfig Config

References XrdOucUtils::doIf(), XrdOucNList_Anchor::Find(), XrdOucNList_Anchor::First(), inList(), XrdOucUtils::InstName(), Logger, XrdNetAddrInfo::Name(), open, optind, optopt, XrdOucNList_Anchor::Replace(), Say, XrdNetAddr::Set(), Usage(), and XrdSysE2T().

+ Here is the call graph for this function:

◆ Usage()

void Usage ( int  rc)

Definition at line 64 of file XrdAppsCconfig.cc.

65{
66 std::cerr <<"\n Usage: cconfig -c <cfn> [-h <host>] [-n <name>] [-x <prog>] [<args>]"
67 "\n<args>: [[pfx]*]<directive> | <directive>[*[sfx]] [<args>]" <<std::endl;
68 exit(rc);
69}

Referenced by main().

+ Here is the caller graph for this function: