Skip to content

Commit

Permalink
[Server] Allow config file to continue to another file (new feature).
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 committed Dec 13, 2017
1 parent 1b31eb7 commit 00cb8ce
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 3 deletions.
89 changes: 86 additions & 3 deletions src/XrdOuc/XrdOucStream.cc
Expand Up @@ -55,6 +55,7 @@
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdOuc/XrdOucStream.hh"
#include "XrdOuc/XrdOucUtils.hh"
#include "XrdSys/XrdSysFD.hh"
#include "XrdSys/XrdSysHeaders.hh"
#include "XrdSys/XrdSysLogger.hh"
#include "XrdSys/XrdSysPlatform.hh"
Expand All @@ -69,6 +70,10 @@
#define XrdOucStream_BUSY 0x02
#define XrdOucStream_ELIF 0x80

#define XrdOucStream_CADD 0x010000
#define XrdOucStream_CONT 0xff0000
#define XrdOucStream_CMAX 0x0f0000

#define Erq(p, a, b) Err(p, a, b, (char *)0)
#define Err(p, a, b, c) (ecode=(Eroute ? Eroute->Emsg(#p, a, b, c) : a), -1)
#define Erp(p, a, b, c) ecode=(Eroute ? Eroute->Emsg(#p, a, b, c) : a)
Expand Down Expand Up @@ -504,15 +509,35 @@ char *XrdOucStream::GetToken(char **rest, int lowcase)

char *XrdOucStream::GetFirstWord(int lowcase)
{
char *theWord;

// If in the middle of a line, flush to the end of the line. Suppress
// variable substitution when doing this to avoid errors.
//
if (xline)
do {if (xline)
{XrdOucEnv *oldEnv = SetEnv(0);
while(GetWord(lowcase)) {}
SetEnv(oldEnv);
}
return GetWord(lowcase);

// Check if this a "continue" statement and is valid in this context
//
theWord = GetWord(lowcase);
if (!myInst || !theWord || strcmp(theWord, "continue")) return theWord;
if (sawif)
{ecode = EINVAL;
if (Eroute)
Eroute->Emsg("Stream", "'continue' invalid within 'if-fi'.");
return 0;
}

// Get the path, if none then ignore this continue
//
theWord = GetWord(lowcase);
if (Eroute) Eroute->Say(llPrefix, "continue ", theWord);
if (!theWord) continue;
if (!docont(theWord)) return 0;
} while(true);
}

/******************************************************************************/
Expand All @@ -536,7 +561,7 @@ char *XrdOucStream::GetMyFirstWord(int lowcase)
}

do {if (!(var = GetFirstWord(lowcase)))
{if (sawif)
{if (sawif && !ecode)
{ecode = EINVAL;
if (Eroute) Eroute->Emsg("Stream", "Missing 'fi' for last 'if'.");
}
Expand Down Expand Up @@ -793,6 +818,64 @@ char *XrdOucStream::add2llB(char *tok, int reset)
}
return tok;
}

/******************************************************************************/
/* d o c o n t */
/******************************************************************************/

bool XrdOucStream::docont(char *path)
{
int cFD;
bool noentok;

// Check if this file must exist (we also take care of empty paths)
//
if ((noentok = (*path == '?')))
{path++;
if (!(*path)) return true;
}

// Open the file and handle any errots
//
if ((cFD = XrdSysFD_Open(path, O_RDONLY)) < 0)
{if (errno == ENOENT && noentok) return true;
if (Eroute)
{Eroute->Emsg("Stream", errno, "open", path);
ecode = ECANCELED;
} else ecode = errno;
return false;
}

// Check if we are continuing too often (possible loop)
//
flags += XrdOucStream_CADD;
if ((flags & XrdOucStream_CONT) > XrdOucStream_CMAX)
{close(cFD);
if (Eroute)
{Eroute->Emsg("Stream", EMLINK, "continue to", path);
ecode = ECANCELED;
} else ecode = EMLINK;
return false;
}

// Continue to the next file
//
if (XrdSysFD_Dup2(cFD, FD) < 0)
{if (Eroute)
{Eroute->Emsg("Stream", ecode, "switch to", path);
close(cFD);
ecode = ECANCELED;
} else ecode = errno;
return false;
}

// Indicate we are switching to anther file
//
if (Eroute) Eroute->Say(llPrefix, "Continuing with file ", path, " ...");
bleft = 0;
return true;
}

/******************************************************************************/
/* d o e l s e */
/******************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions src/XrdOuc/XrdOucStream.hh
Expand Up @@ -207,6 +207,7 @@ int Wait4Data(int msMax=-1);

private:
char *add2llB(char *tok, int reset=0);
bool docont(char *path);
char *doelse();
char *doif();
int isSet(char *var);
Expand Down

0 comments on commit 00cb8ce

Please sign in to comment.