326 const char *xrdInst=
"XRDINSTANCE=";
328 int retc, NoGo = 0, clPort = -1;
330 char c, buff[512], *dfltProt, *libProt = 0;
334 extern int optind, opterr;
336 int pipeFD[2] = {-1, -1};
337 const char *pidFN = 0;
338 static const int myMaxc = 80;
339 char **urArgv, *myArgv[myMaxc], argBuff[myMaxc*3+8];
340 char *argbP = argBuff, *argbE = argbP+
sizeof(argBuff)-4;
342 int myArgc = 1, urArgc = argc, i;
343 bool noV6, ipV4 =
false, ipV6 =
false, rootChk =
true, optbg =
false;
348 for (
int k = 1; k < argc; k++)
349 {CmdLine +=
' '; CmdLine += argv[k];}
353 retc = strlen(argv[0]);
354 while(retc--)
if (argv[0][retc] ==
'/')
break;
355 myProg = &argv[0][retc+1];
362 {
char *p = dfltProt = strdup(myProg);
363 while(*p && (*p ==
'.' || *p ==
'-')) p++;
365 {
char *dot = index(p,
'.'), *dash = index(p,
'-');
366 if (dot && (dot < dash || !dash)) p = dot;
367 else if (dash) p = dash;
370 if (!strcmp(
"xrootd", dfltProt)) dfltProt[5] = 0;
371 else if (!strcmp(
"cmsd", dfltProt)) dfltProt[3] = 0;
381 {
if (*(argv[i]) ==
'-' && *(argv[i]+1) ==
'+')
382 {
int n = strlen(argv[i]+2), j = i+1, k = 1;
383 if (urArgc == argc) urArgc = i;
384 if (n) memcpy(buff, argv[i]+2, (n > 256 ? 256 : n));
385 strcpy(&(buff[n]),
".argv**");
386 while(j < argc && (*(argv[j]) !=
'-' || *(argv[j]+1) !=
'+')) j++;
387 urArgv =
new char*[j-i+1];
390 while(i < j) urArgv[k++] = argv[i++];
393 strcpy(&(buff[n]),
".argc");
403 if (argc > 1 &&
'-' == *argv[1])
404 while ((c = getopt(urArgc,argv,
":a:A:bc:dhHI:k:l:L:n:p:P:R:s:S:vw:W:z"))
405 && ((
unsigned char)c != 0xff))
408 case 'a':
if (AdminPath) free(AdminPath);
409 AdminPath = strdup(optarg);
413 case 'A':
if (AdminPath) free(AdminPath);
414 AdminPath = strdup(optarg);
418 case 'b': optbg =
true;
420 case 'c':
if (ConfigFN) free(ConfigFN);
421 ConfigFN = strdup(optarg);
431 case 'I':
if (!strcmp(
"v4", optarg)) {ipV4 =
true; ipV6 =
false;}
432 else if (!strcmp(
"v6", optarg)) {ipV4 =
false; ipV6 =
true;}
433 else {
Log.
Emsg(
"Config",
"Invalid -I argument -",optarg);
438 {
Log.
Emsg(
"Config",
"Invalid -k argument -",optarg);
442 case 'l': LogInfo.logArg = optarg;
444 case 'L':
if (!*optarg)
445 {
Log.
Emsg(
"Config",
"Protocol library path not specified.");
448 if (libProt) free(libProt);
449 libProt = strdup(optarg);
451 case 'n': myInsName = (!strcmp(optarg,
"anon")||!strcmp(optarg,
"default")
456 case 'P':
if (dfltProt) free(dfltProt);
457 dfltProt = strdup(optarg);
459 case 'R':
if (!(getUG(optarg, myUid, myGid)))
Usage(1);
462 case 's': pidFN = optarg;
464 case 'S': mySitName = optarg;
466 case ':': buff[0] =
'-'; buff[1] =
optopt; buff[2] = 0;
467 Log.
Emsg(
"Config", buff,
"parameter not specified.");
470 case 'v': std::cerr <<XrdVSTRING <<std::endl;
473 case 'w':
if (HomePath) free(HomePath);
474 HomePath = strdup(optarg);
478 case 'W':
if (HomePath) free(HomePath);
479 HomePath = strdup(optarg);
480 HomeMode = S_IRWXU | S_IRGRP | S_IXGRP;
483 case 'z': LogInfo.hiRes =
true;
487 {
Log.
Emsg(
"Config",
"Long options are not supported.");
490 if (myArgc >= myMaxc || argbP >= argbE)
491 {
Log.
Emsg(
"Config",
"Too many command line arguments.");
494 myArgv[myArgc++] = argbP;
495 *argbP++ =
'-'; *argbP++ =
optopt; *argbP++ = 0;
503 {
Log.
Emsg(
"Config",
"Command line adminpath is not absolute.");
509 if (HomePath && *HomePath !=
'/')
510 {
Log.
Emsg(
"Config",
"Command line home path is not absolute.");
517 if (ConfigFN) setCFG(
true);
523 else if (ipV6){
if (noV6)
Log.
Say(
"Config warning: ipV6 appears to be broken;"
524 " forced ipV6 mode not advised!");
527 else if (noV6)
Log.
Say(
"Config warning: ipV6 is misconfigured or "
528 "unavailable; reverting to ipV4.");
536 if (myGid && setegid(myGid))
537 {
Log.
Emsg(
"Config", errno,
"set effective gid"); exit(17);}
538 if (myUid && seteuid(myUid))
539 {
Log.
Emsg(
"Config", errno,
"set effective uid"); exit(17);}
543 if (rootChk && geteuid() == 0)
544 {
Log.
Emsg(
"Config",
"Security reasons prohibit running as "
545 "superuser; program is terminating.");
551 if (urArgc-
optind+2 >= myMaxc)
552 {
Log.
Emsg(
"Config",
"Too many command line arguments.");
570 if (pipe( pipeFD ) == -1)
571 {
Log.
Emsg(
"Config", errno,
"create a pipe"); exit(17);}
580 if (!(myName = myIPAddr->
Name(0, &temp))) myName =
"";
593 sprintf(buff,
"%s%s %s@%s", xrdInst, myProg,
ProtInfo.
myInst, myName);
594 myInstance = strdup(buff);
596 myInstance += strlen(xrdInst);
604 {LogInfo.xrdEnv = &
theEnv;
605 LogInfo.iName = myInsName;
606 LogInfo.cfgFn = ConfigFN;
617 {
Log.
Emsg(
"Config",
"Unable to determine host name; ",
618 (temp ? temp :
"reason unknown"),
619 "; execution terminated.");
629 strcpy(buff,
"Starting on ");
633 Log.
Say(0, CmdLine.c_str());
641 {
Log.
Emsg(
"Config",myName,
"does not appear to be registered in the DNS.");
642 Log.
Emsg(
"Config",
"Verify that the '/etc/hosts' file is correct and "
643 "this machine is registered in DNS.");
644 Log.
Emsg(
"Config",
"Execution continues but connection failures may occur.");
646 }
else if (!(
myDomain = index(myName,
'.')))
647 Log.
Say(
"Config warning: this hostname, ", myName,
648 ", is registered without a domain qualification.");
652 Firstcp = Lastcp =
new XrdConfigProt(strdup(dfltProt), libProt, 0);
656 Log.
Say(
"++++++ ", myInstance,
" initialization started.");
660 devNull = XrdSysFD_Open(
"/dev/null", O_RDONLY);
662 {
Log.
Emsg(
"Config", errno,
"open '/dev/null' which is required!");
669 {
Log.
Say(
"Config using configuration file ", ConfigFN);
673 if (clPort >= 0) PortTCP = clPort;
681 NoGo |= SetupAPath();
687 else {
Log.
Say(
"++++++ ", myInstance,
" TLS initialization started.");
689 {
Log.
Say(
"------ ",myInstance,
" TLS initialization ended.");
694 Log.
Say(
"------ ",myInstance,
" TLS initialization failed.");
704 {
Log.
Say(
"Config TLS port specification ignored; TLS not configured!");
724 {
Log.
Emsg(
"Config",
"Unable to determine interface addresses!");
730 if ((myInsName || HomePath)
735 if (!PidFile(pidFN, optbg)) NoGo = 1;
739 if (!NoGo) Manifest(pidFN);
743 if (!NoGo) NoGo = Setup(dfltProt, libProt);
752 if (tmoInfo && !NoGo)
754 if (!theGS)
Log.
Say(
"Config warning: TCP monitoring not enabled; "
755 "tcpmonlib plugin not loaded!");
767 int status = NoGo ? 1 : 0;
768 if(
write( pipeFD[1], &status,
sizeof( status ) )) {};
775 temp = (NoGo ?
" initialization failed." :
" initialization completed.");
776 sprintf(buff,
"%s:%d", myInstance, PortTCP);
777 Log.
Say(
"------ ", buff, temp);
779 {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)
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