327 const char *xrdInst=
"XRDINSTANCE=";
329 int retc, NoGo = 0, clPort = -1;
331 char c, buff[512], *dfltProt, *libProt = 0;
335 extern int optind, opterr;
337 int pipeFD[2] = {-1, -1};
338 const char *pidFN = 0;
339 static const int myMaxc = 80;
340 char **urArgv, *myArgv[myMaxc], argBuff[myMaxc*3+8];
341 char *argbP = argBuff, *argbE = argbP+
sizeof(argBuff)-4;
343 int myArgc = 1, urArgc = argc, i;
344 bool noV6, ipV4 =
false, ipV6 =
false, rootChk =
true, optbg =
false;
349 for (
int k = 1; k < argc; k++)
350 {CmdLine +=
' '; CmdLine += argv[k];}
354 retc = strlen(argv[0]);
355 while(retc--)
if (argv[0][retc] ==
'/')
break;
356 myProg = &argv[0][retc+1];
363 {
char *p = dfltProt = strdup(myProg);
364 while(*p && (*p ==
'.' || *p ==
'-')) p++;
366 {
char *dot = index(p,
'.'), *dash = index(p,
'-');
367 if (dot && (dot < dash || !dash)) p = dot;
368 else if (dash) p = dash;
371 if (!strcmp(
"xrootd", dfltProt)) dfltProt[5] = 0;
372 else if (!strcmp(
"cmsd", dfltProt)) dfltProt[3] = 0;
382 {
if (*(argv[i]) ==
'-' && *(argv[i]+1) ==
'+')
383 {
int n = strlen(argv[i]+2), j = i+1, k = 1;
384 if (urArgc == argc) urArgc = i;
385 if (n) memcpy(buff, argv[i]+2, (n > 256 ? 256 : n));
386 strcpy(&(buff[n]),
".argv**");
387 while(j < argc && (*(argv[j]) !=
'-' || *(argv[j]+1) !=
'+')) j++;
388 urArgv =
new char*[j-i+1];
391 while(i < j) urArgv[k++] = argv[i++];
394 strcpy(&(buff[n]),
".argc");
404 if (argc > 1 &&
'-' == *argv[1])
405 while ((c = getopt(urArgc,argv,
":a:A:bc:dhHI:k:l:L:n:N:p:P:R:s:S:vw:W:z"))
406 && ((
unsigned char)c != 0xff))
409 case 'a':
if (AdminPath) free(AdminPath);
410 AdminPath = strdup(optarg);
414 case 'A':
if (AdminPath) free(AdminPath);
415 AdminPath = strdup(optarg);
419 case 'b': optbg =
true;
421 case 'c':
if (ConfigFN) free(ConfigFN);
422 ConfigFN = strdup(optarg);
432 case 'I':
if (!strcmp(
"v4", optarg)) {ipV4 =
true; ipV6 =
false;}
433 else if (!strcmp(
"v6", optarg)) {ipV4 =
false; ipV6 =
true;}
434 else {
Log.
Emsg(
"Config",
"Invalid -I argument -",optarg);
439 {
Log.
Emsg(
"Config",
"Invalid -k argument -",optarg);
443 case 'l': LogInfo.logArg = optarg;
445 case 'L':
if (!*optarg)
446 {
Log.
Emsg(
"Config",
"Protocol library path not specified.");
449 if (libProt) free(libProt);
450 libProt = strdup(optarg);
452 case 'n': myInsName = (!strcmp(optarg,
"anon")||!strcmp(optarg,
"default")
459 case 'P':
if (dfltProt) free(dfltProt);
460 dfltProt = strdup(optarg);
462 case 'R':
if (!(getUG(optarg, myUid, myGid)))
Usage(1);
465 case 's': pidFN = optarg;
467 case 'S': mySitName = optarg;
469 case ':': buff[0] =
'-'; buff[1] =
optopt; buff[2] = 0;
470 Log.
Emsg(
"Config", buff,
"parameter not specified.");
473 case 'v': std::cerr <<XrdVSTRING <<std::endl;
476 case 'w':
if (HomePath) free(HomePath);
477 HomePath = strdup(optarg);
481 case 'W':
if (HomePath) free(HomePath);
482 HomePath = strdup(optarg);
483 HomeMode = S_IRWXU | S_IRGRP | S_IXGRP;
486 case 'z': LogInfo.hiRes =
true;
490 {
Log.
Emsg(
"Config",
"Long options are not supported.");
493 if (myArgc >= myMaxc || argbP >= argbE)
494 {
Log.
Emsg(
"Config",
"Too many command line arguments.");
497 myArgv[myArgc++] = argbP;
498 *argbP++ =
'-'; *argbP++ =
optopt; *argbP++ = 0;
506 {
Log.
Emsg(
"Config",
"Command line adminpath is not absolute.");
512 if (HomePath && *HomePath !=
'/')
513 {
Log.
Emsg(
"Config",
"Command line home path is not absolute.");
520 if (ConfigFN) setCFG(
true);
526 else if (ipV6){
if (noV6)
Log.
Say(
"Config warning: ipV6 appears to be broken;"
527 " forced ipV6 mode not advised!");
530 else if (noV6)
Log.
Say(
"Config warning: ipV6 is misconfigured or "
531 "unavailable; reverting to ipV4.");
539 if (myGid && setegid(myGid))
540 {
Log.
Emsg(
"Config", errno,
"set effective gid"); exit(17);}
541 if (myUid && seteuid(myUid))
542 {
Log.
Emsg(
"Config", errno,
"set effective uid"); exit(17);}
546 if (rootChk && geteuid() == 0)
547 {
Log.
Emsg(
"Config",
"Security reasons prohibit running as "
548 "superuser; program is terminating.");
554 if (urArgc-
optind+2 >= myMaxc)
555 {
Log.
Emsg(
"Config",
"Too many command line arguments.");
573 if (pipe( pipeFD ) == -1)
574 {
Log.
Emsg(
"Config", errno,
"create a pipe"); exit(17);}
583 auto envName = getenv(
"XRDHOST");
584 const char *ipAddrName;
588 }
else if ((ipAddrName = myIPAddr->
Name(0, &temp))) {
605 sprintf(buff,
"%s%s %s@%s", xrdInst, myProg,
ProtInfo.
myInst, myName.c_str());
606 myInstance = strdup(buff);
608 myInstance += strlen(xrdInst);
616 {LogInfo.xrdEnv = &
theEnv;
617 LogInfo.iName = myInsName;
618 LogInfo.cfgFn = ConfigFN;
629 {
Log.
Emsg(
"Config",
"Unable to determine host name; ",
630 (temp ? temp :
"reason unknown"),
631 "; execution terminated.");
641 strcpy(buff,
"Starting on ");
645 Log.
Say(0, CmdLine.c_str());
653 {
Log.
Emsg(
"Config",myName.c_str(),
"does not appear to be registered in the DNS.");
654 Log.
Emsg(
"Config",
"Verify that the '/etc/hosts' file is correct and "
655 "this machine is registered in DNS.");
656 Log.
Emsg(
"Config",
"Execution continues but connection failures may occur.");
658 }
else if (!(
myDomain = index(myName.c_str(),
'.')))
659 Log.
Say(
"Config warning: this hostname, ", myName.c_str(),
660 ", is registered without a domain qualification.");
664 Firstcp = Lastcp =
new XrdConfigProt(strdup(dfltProt), libProt, 0);
668 Log.
Say(
"++++++ ", myInstance,
" initialization started.");
672 devNull = XrdSysFD_Open(
"/dev/null", O_RDONLY);
674 {
Log.
Emsg(
"Config", errno,
"open '/dev/null' which is required!");
681 {
Log.
Say(
"Config using configuration file ", ConfigFN);
685 if (clPort >= 0) PortTCP = clPort;
693 NoGo |= SetupAPath();
699 else {
Log.
Say(
"++++++ ", myInstance,
" TLS initialization started.");
701 {
Log.
Say(
"------ ",myInstance,
" TLS initialization ended.");
706 Log.
Say(
"------ ",myInstance,
" TLS initialization failed.");
716 {
Log.
Say(
"Config TLS port specification ignored; TLS not configured!");
736 {
Log.
Emsg(
"Config",
"Unable to determine interface addresses!");
742 if ((myInsName || HomePath)
747 if (!PidFile(pidFN, optbg)) NoGo = 1;
751 if (!NoGo) Manifest(pidFN);
755 if (!NoGo) NoGo = Setup(dfltProt, libProt);
764 if (tmoInfo && !NoGo)
766 if (!theGS)
Log.
Say(
"Config warning: TCP monitoring not enabled; "
767 "tcpmonlib plugin not loaded!");
779 int status = NoGo ? 1 : 0;
780 if(
write( pipeFD[1], &status,
sizeof( status ) )) {};
787 temp = (NoGo ?
" initialization failed." :
" initialization completed.");
788 sprintf(buff,
"%s:%d", myInstance, PortTCP);
789 Log.
Say(
"------ ", buff, temp);
791 {strcat(buff,
" running ");
void Usage(const char *msg)
ssize_t write(int fildes, const void *buf, size_t nbyte)
const sockaddr * SockAddr()
const char * Name(const char *eName=0, const char **eText=0)
static int GetIF(XrdOucTList **ifList, const char **eText=0)
static void SetMsgs(XrdSysError *erp)
static void SetFQN(const char *fqn)
void PutInt(const char *varname, long value)
static int Export(const char *Var, const char *Val)
void * GetPtr(const char *varname)
void PutPtr(const char *varname, void *value)
static bool configLog(XrdSysError &eDest, configLogInfo &logInfo)
T * Load(const char *Symbol)
static const char * Set(const char *name, int maxlen=15)
static const char * InstName(int TranOpt=0)
static void makeHome(XrdSysError &eDest, const char *inst)
static void Undercover(XrdSysError &eDest, int noLog, int *pipeFD=0)
static int a2p(XrdSysError &, const char *ptype, const char *val, bool anyOK=true)
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)
void AddMsg(const char *msg)
int ParseKeep(const char *arg)
static void setDebug(XrdSysError *erp)
static int FmtUname(char *buff, int blen)
XrdOucPinKing< XrdTcpMonPin > KingPin