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

Heikki Linnakangas hlinnaka at iki.fi
Mon Feb 5 23:15:56 UTC 2024


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




More information about the Dnsmasq-discuss mailing list