[Dnsmasq-discuss] Don't set up inotify watch on resolv.conf if --port=0

Petr Menšík pemensik at redhat.com
Thu Feb 8 14:05:27 UTC 2024


This is merged by 
https://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=commit;h=762a3f243099d26b1e87aad2b1b4b696cd8c33ac

Simon has added description for it.

On 06. 02. 24 0:15, Heikki Linnakangas wrote:
> On 05/02/2024 22:52, Geert Stappers wrote:
>> On Mon, Feb 05, 2024 at 08:47:54PM +0200, Heikki Linnakangas wrote:
>>> diff --git a/src/inotify.c b/src/inotify.c
>>> index a944c62..0c775de 100644
>>> --- a/src/inotify.c
>>> +++ b/src/inotify.c
>>> @@ -94,7 +94,7 @@ void inotify_dnsmasq_init()
>>>     if (daemon->inotifyfd == -1)
>>>       die(_("failed to create inotify: %s"), NULL, EC_MISC);
>>>   -  if (option_bool(OPT_NO_RESOLV))
>>> +  if (daemon->port == 0 || option_bool(OPT_NO_RESOLV))
>>
>> Nice and clean
>
> Thanks!
>
>>> diff --git a/src/dnsmasq.c b/src/dnsmasq.c
>>> index ce897ae..5520511 100644
>>> --- a/src/dnsmasq.c
>>> +++ b/src/dnsmasq.c
>>> @@ -429,8 +429,8 @@ int main (int argc, char **argv)
>>>       }
>>>     #ifdef HAVE_INOTIFY
>>> -  if ((daemon->port != 0 || daemon->dhcp || daemon->doing_dhcp6)
>>> -      && (!option_bool(OPT_NO_RESOLV) || daemon->dynamic_dirs))
>>> +  if ((daemon->port != 0 && !option_bool(OPT_NO_RESOLV))
>>> +      || ((daemon->dhcp || daemon->doing_dhcp6) && 
>>> daemon->dynamic_dirs))
>>
>> Mmm, not so clean.  So I didn't give it further attention.
>
> The point is to avoid calling inotify_init1() and creating an inotify 
> fd, if inotify is not used. My thinking was that inotify is used for 
> two things:
>
> 1. To watch for resolv_files. Only if port != 0 and --no-resolv was 
> not given.
> 2. To watch for dhcp-hostsdir, dhcp-optsdir and hostsdir. Only if DHCP 
> is enabled.
>
> Hmm, I think I got 2. wrong: the --hostsdir option also affects DNS 
> replies. I'm not sure what exactly the conditions here should be. This 
> is one alternative:
>
>   if ((daemon->port != 0 && !option_bool(OPT_NO_RESOLV))
>       || daemon->dynamic_dirs)
>
> But that'd still create the inotify fd unnecessarily e.g if you 
> specify --dhcp-optsdir but no --dhcp-range. (Admittedly that's a silly 
> combination.)
>
> - Heikki
>
>
> _______________________________________________
> Dnsmasq-discuss mailing list
> Dnsmasq-discuss at lists.thekelleys.org.uk
> https://lists.thekelleys.org.uk/cgi-bin/mailman/listinfo/dnsmasq-discuss
>
-- 
Petr Menšík
Software Engineer, RHEL
Red Hat, http://www.redhat.com/
PGP: DFCF908DB7C87E8E529925BC4931CA5B6C9FC5CB




More information about the Dnsmasq-discuss mailing list