From 762a3f243099d26b1e87aad2b1b4b696cd8c33ac Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Wed, 7 Feb 2024 14:44:49 +0000 Subject: [PATCH] Don't create a useless inotify file desrcriptor when --port=0 If there are no dynamic configuration directories configured with dhcp-hostsdir, dhcp-optsdir and hostsdir then we need to use inotify only to track changes to resolv-files, but we don't need to do that when DNS is disabled (port=0) or no resolv-files are configured. It turns out that inotify slots can be a scarce resource, so not using one when it's not needed is a Goood Thing. Patch by HL, description above from SRK. --- 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 db970b3..30fb419 100644 --- a/src/dnsmasq.c +++ b/src/dnsmasq.c @@ -421,8 +421,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->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)