Skip to content

Commit

Permalink
Merge pull request #5357 from larsewi/interface
Browse files Browse the repository at this point in the history
ENT-9402: Moved ignore_interfaces.rx to $(sys.workdir)
  • Loading branch information
larsewi authored Nov 2, 2023
2 parents 7d138ad + 301a764 commit 573d038
Showing 1 changed file with 54 additions and 8 deletions.
62 changes: 54 additions & 8 deletions libenv/unix_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,24 +836,70 @@ static void FindV6InterfacesInfo(EvalContext *ctx, Rlist **interfaces, Rlist **h
static void InitIgnoreInterfaces()
{
FILE *fin;
char filename[CF_BUFSIZE],regex[256];
char filename[CF_BUFSIZE], regex[256];

int ret = snprintf(
filename,
sizeof(filename),
"%s%c%s",
GetWorkDir(),
FILE_SEPARATOR,
CF_IGNORE_INTERFACES);
assert(ret >= 0 && (size_t) ret < sizeof(filename));

if ((fin = fopen(filename, "r")) == NULL)
{
Log((errno == ENOENT) ? LOG_LEVEL_VERBOSE : LOG_LEVEL_ERR,
"Failed to open interface exception file %s: %s",
filename,
GetErrorStr());

snprintf(filename, sizeof(filename), "%s%c%s", GetInputDir(), FILE_SEPARATOR, CF_IGNORE_INTERFACES);
/* LEGACY: The 'ignore_interfaces.rx' file was previously located in
* $(sys.inputdir). Consequently, if the file is found in this
* directory but not in $(sys.workdir), we will still process it, but
* issue a warning. */
ret = snprintf(
filename,
sizeof(filename),
"%s%c%s",
GetInputDir(),
FILE_SEPARATOR,
CF_IGNORE_INTERFACES);
assert(ret >= 0 && (size_t) ret < sizeof(filename));

if ((fin = fopen(filename, "r")) == NULL)
{
Log((errno == ENOENT) ? LOG_LEVEL_VERBOSE : LOG_LEVEL_ERR,
"Failed to open interface exception file %s: %s",
filename,
GetErrorStr());
return;
}

if ((fin = fopen(filename,"r")) == NULL)
{
Log(LOG_LEVEL_VERBOSE, "No interface exception file %s",filename);
return;
Log(LOG_LEVEL_WARNING,
"Found interface exception file %s in %s but it should be in %s. "
"Please consider moving it to the appropriate location.",
CF_IGNORE_INTERFACES,
GetInputDir(),
GetWorkDir());
}

while (!feof(fin))
{
regex[0] = '\0';
int scanCount = fscanf(fin,"%255s",regex);
int scanCount = fscanf(fin, "%255s", regex);
if (ferror(fin) != 0)
{
Log(LOG_LEVEL_ERR,
"Failed to read interface exception file %s: %s",
filename,
GetErrorStr());
break;
}

if (scanCount != 0 && *regex != '\0')
{
RlistPrependScalarIdemp(&IGNORE_INTERFACES, regex);
RlistPrependScalarIdemp(&IGNORE_INTERFACES, regex);
}
}

Expand Down

0 comments on commit 573d038

Please sign in to comment.