Include order

Hi

I was having a problem with my puppet-generated nsd-config: it worked
on one and did not work on the other host.
That was very confusing for me as everything was based on the same
templates and the configs were mostly identical (apart from
hostnames/IPs).

After some debugging with the help of a friend the cause was found:
the 'include' directive does not do what I expected it to do when
using globbing, which is including the files in lexical order.
It actually includes the files in "directory order".

This directory order was different for the two hosts since puppet
decided the order in which it created files and that happened to be
different for the two hosts.
The result was that the file with additional "server"-settings was
included after the files providing "pattern"s and "zone"s and thus I
got a "syntax error".

IMHO the files should be included in lexical order.
That’s what people usually expect, as that is what (most) other
software does, e.g. run-parts.

Is there any reason why "GLOB_NOSORT" and thus "directory order" is
used?
Could it be changed to include globbed files in lexical order?

Thank you

Hendrik Jäger

Hi Hendrik,

Hi

I was having a problem with my puppet-generated nsd-config: it worked
on one and did not work on the other host.
That was very confusing for me as everything was based on the same
templates and the configs were mostly identical (apart from
hostnames/IPs).

After some debugging with the help of a friend the cause was found:
the 'include' directive does not do what I expected it to do when
using globbing, which is including the files in lexical order.
It actually includes the files in "directory order".

This directory order was different for the two hosts since puppet
decided the order in which it created files and that happened to be
different for the two hosts.
The result was that the file with additional "server"-settings was
included after the files providing "pattern"s and "zone"s and thus I
got a "syntax error".

IMHO the files should be included in lexical order.
That’s what people usually expect, as that is what (most) other
software does, e.g. run-parts.

Is there any reason why "GLOB_NOSORT" and thus "directory order" is
used?
Could it be changed to include globbed files in lexical order?

I guess it was for performance, but you are right, predictable outcome
for include wildcard processing is important for stable system services.
Fixed it. Thanks for the report!

Best regards, Wouter

Hi

I am having a strange behavior when using the include directive with globbing.

The intention is, to have some “conf.d”, where I have my configuration files. The configuration files are prefixed with a number, e.g.

10-test.conf → Content “foo”
20-test.conf → Content “bar”

I would expect NSD to include the files in this order. However, restarting the service or running nsd-checkconf tells me this:

/etc/nsd/conf.d/20-test.conf:1: at ‘bar’: error: syntax error
read /etc/nsd/nsd.conf failed: 1 errors in configuration file

I tried several other prefixes (number or letter).
It looks like the files are parsed in a somewhat arbitrary order. I can reproduce this with the NSD packages from several distributions, Debian 9, Debian 10, CentOS 7, Arch …

I found this line in the lexer

which to me indicates, that a sorted/predictable outcome for including files is desired and should work.

Is this me doing something wrong? Can anyone else reproduce/explain this behaviour?

Best regards
Andreas

Hi Andreas,