XRootD
Loading...
Searching...
No Matches
XrdAppsCconfig.cc File Reference
#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"
+ Include dependency graph for XrdAppsCconfig.cc:

Go to the source code of this file.

Functions

int cfOut (const char *outFN, XrdOucString &cFile)
 
int inList (const char *var, const char **Vec)
 
int main (int argc, char *argv[])
 
void Usage (int rc)
 

Function Documentation

◆ cfOut()

int cfOut ( const char * outFN,
XrdOucString & cFile )

Definition at line 78 of file XrdAppsCconfig.cc.

79{
80
81// Open the output file
82//
83 int mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
84 int fd = open(outFN, O_CREAT | O_TRUNC | O_WRONLY, mode);
85 if (fd < 0)
86 {Say.Say(Pgm, XrdSysE2T(errno), " opening output file ", outFN);
87 return 8;
88 }
89
90// Write out the config file
91//
92 if (write(fd, cFile.c_str(), cFile.length()) != cFile.length())
93 {Say.Say(Pgm, XrdSysE2T(errno), " writing output file ", outFN);
94 return 1;
95 }
96
97// All done
98//
99 close(fd);
100 return 0;
101}
XrdOucPup XrdCmsParser::Pup & Say
#define close(a)
Definition XrdPosix.hh:43
#define write(a, b, c)
Definition XrdPosix.hh:110
#define open
Definition XrdPosix.hh:71
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:99
int length() const
const char * c_str() const

References XrdOucString::c_str(), close, XrdOucString::length(), open, Say, write, and XrdSysE2T().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inList()

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

Definition at line 67 of file XrdAppsCconfig.cc.

68{
69 int i = 0;
70 while(Vec[i] && strcmp(Vec[i],var)) i++;
71 return (Vec[i] != 0);
72}

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

+ Here is the caller graph for this function:

◆ main()

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

Definition at line 120 of file XrdAppsCconfig.cc.

121{
122 extern char *optarg;
123 extern int opterr, optind, optopt;
124
126 XrdOucEnv myEnv, *oldEnv = 0;
128 XrdNetAddr theAddr(0);
129
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};
135
136 char buff[4096], *var, c;
137 int i, retc = 0, cfgFD, chkQ = 0;
138
139// Process the options
140//
141 opterr = 0;
142 if (argc > 1 && '-' == *argv[1])
143 while ((c = getopt(argc,argv,":c:h:n:o:x:")) && ((unsigned char)c != 0xff))
144 { switch(c)
145 {
146 case 'c': Cfn = optarg;
147 break;
148 case 'h': Host= optarg;
149 break;
150 case 'n': Name= optarg;
151 break;
152 case 'o': oFile=optarg;
153 break;
154 case 'x': Xeq = optarg;
155 break;
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.");
159 Usage(1);
160 }
161 }
162
163// Make sure config file has been specified
164//
165 if (!Cfn) {Say.Say(Pgm, "Config file not specified."); Usage(1);}
166
167// Get full host name
168//
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);}
172
173// Prepare all selector arguments
174//
175 for (i = optind; i < argc; i++) DirQ.Replace(argv[i],0);
176 chkQ = (DirQ.First() != 0);
177
178// Open the config file
179//
180 if ( (cfgFD = open(Cfn, O_RDONLY, 0)) < 0)
181 {Say.Say(Pgm, XrdSysE2T(errno), " opening config file ", Cfn);
182 exit(4);
183 }
184
185// Construct instance name and stream
186//
187 Name = XrdOucUtils::InstName(Name);
188 sprintf(buff,"%s %s@%s", Xeq, Name, Host);
189 Config = new XrdOucStream(&Say, strdup(buff), &myEnv, "");
190 Config->Attach(cfgFD);
191
192// We will capture the resulting config file for later
193//
194 XrdOucString theConfig;
195 Config->Capture(&theConfig);
196
197// Now start reading records until eof.
198//
199 while((var = Config->GetMyFirstWord()))
200 {if (chkQ && !DirQ.Find(var)) {Config->noEcho(); continue;}
201 if (inList(var, noSub))
202 {if (inList(var, slChk))
203 while((var = Config->GetWord()) && *var != '/') {}
204 oldEnv = Config->SetEnv(0);
205 if (var) Config->GetRest(buff, sizeof(buff));
206 Config->SetEnv(oldEnv);
207 }
208 else if (inList(var, ifChk))
209 {while((var = Config->GetWord()) && strcmp(var, "if")) {}
210 if (var && !XrdOucUtils::doIf(&Say, *Config, "directive",
211 Host, Name, Xeq))
212 {Config->noEcho(); continue;}
213 }
214 else Config->GetRest(buff, sizeof(buff));
215 Config->Echo();
216 }
217
218// Now check if any errors occurred during file i/o
219//
220 if ((retc = Config->LastError()))
221 {Say.Say(Pgm, XrdSysE2T(retc), " reading config file ", Cfn); retc = 8;}
222 Config->Close();
223
224// Output the config file upon success if so wanted
225//
226 if (oFile && !retc) retc = cfOut(oFile, theConfig);
227
228// Should never get here
229//
230 exit(retc);
231}
int inList(const char *var, const char **Vec)
void Usage(int rc)
int cfOut(const char *outFN, XrdOucString &cFile)
int optopt
int optind
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 cfOut(), XrdOucUtils::doIf(), XrdOucNList_Anchor::Find(), XrdOucNList_Anchor::First(), inList(), XrdOucUtils::InstName(), 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 107 of file XrdAppsCconfig.cc.

108{
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>]"
112 <<std::endl;
113 exit(rc);
114}

Referenced by main().

+ Here is the caller graph for this function: