[Dnsmasq-discuss] Can use sub-directories in addn-hosts?
Simon Kelley
simon at thekelleys.org.uk
Thu Oct 18 16:08:33 BST 2012
On 18/10/12 15:46, David Rosenstrauch wrote:
> On 10/18/2012 02:30 AM, Simon Kelley wrote:
>> From the man page for the current version of dnsmasq: If yours doesn't
>> say this, you may have to upgrade: I can't find the exact version at
>> which the directory-reading facility was added, but it was fairly long
>> ago.
>>
>> -H, --addn-hosts=<file>
>> Additional hosts file. Read the specified file as well as
>> /etc/hosts. If -h is given, read only the specified file. This
>> option may be repeated for more than one additional hosts file.
>> If a directory is given, then read all the files contained in
>> that directory.
>>
>> Cheers,
>>
>> Simon
>
> Yes, I've already read that.
>
> So reading between the lines from what that man page says, it sounds
> like the answer is: no, dnsmasq is not able to handle a parent/child
> directory structure for --addn-hosts.
>
>
> Just to clarify what I'm trying to do. (Since it sounds like you may
> not have understood).
>
> I'm already doing this (which works):
>
> --addn-hosts=<hosts-dir>
>
> where <hosts-dir> looks like:
>
> <hosts-dir>/hosts-file-1
> <hosts-dir>/hosts-file-2
> ...
> <hosts-dir>/hosts-file-n
>
>
> What I'm trying to do is this:
>
> --addn-hosts=<hosts-dir>
>
> <hosts-dir>/subdir-a/hosts-file-a1
> <hosts-dir>/subdir-a/hosts-file-a2
> <hosts-dir>/subdir-b/hosts-file-b1
> ...
> <hosts-dir>/subdir-n/hosts-file-n1
>
Understood. I'm guilty of not reading your initial post carefully.
No, addn-hosts will not follow multiple directory levels. I'm
unconvinced that would be a good feature to have in general: the
potential for unexpected effects seems rather high.
However, looking at the code, I think it would be a trivial code change
to change the behaviour if you wanted to patch.
In expand_filelist() in src/option.c change this code
/* inactivate record if not regular file */
if ((ah1->flags & AH_DIR) && stat(ah1->fname, &buf) != -1 &&
!S_ISREG(buf.st_mode))
ah1->flags |= AH_INACTIVE;
to
/* inactivate record if not regular file or directory */
if ((ah1->flags & AH_DIR) && stat(ah1->fname, &buf) != -1 &&
!(S_ISREG(buf.st_mode) || S_ISDIR(buf.st_mode))
ah1->flags |= AH_INACTIVE;
Cheers,
Simon.
More information about the Dnsmasq-discuss
mailing list