Hi,

I'm using dnsmasq as a DHCP server only, with --port=0. My system has very low limits on inotify watches, and sometimes it fails to start up with:

dnsmasq: failed to create inotify: No file descriptors available

I could raise the limits with systctl, but I started to wonder why dnsmasq is creating an inotify watch in the first place, as my configuration does not depend on any configuration files.

Please see the attached patch. It skips creating the inotify watch on resolv.conf, when --port=0 is used. AFAICS, any such notifications were ignored anyway.

- Heikki
From 9f0c1b1c6fc2d2ddbeaa41c84c145355755d10a9 Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <heikki.linnakan...@iki.fi>
Date: Mon, 5 Feb 2024 20:22:06 +0200
Subject: [PATCH 1/1] Don't set up inotify watch on resolv.conf if --port==0

If dnsmasq is used in DHCP-only mode, i.e. --port==0, resolv.conf is
not used for anything. No need to set up inotify watch on it in that
case.
---
 src/dnsmasq.c | 4 ++--
 src/inotify.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

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))
     inotify_dnsmasq_init();
   else
     daemon->inotifyfd = -1;
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))
     return;
   
   for (res = daemon->resolv_files; res; res = res->next)
-- 
2.39.2

_______________________________________________
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
https://lists.thekelleys.org.uk/cgi-bin/mailman/listinfo/dnsmasq-discuss

Reply via email to