惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
小众软件
小众软件
F
Fortinet All Blogs
爱范儿
爱范儿
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
C
Check Point Blog
博客园 - 聂微东
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
Vercel News
Vercel News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
A
About on SuperTechFans
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog
宝玉的分享
宝玉的分享
Jina AI
Jina AI
H
Hackread – Cybersecurity News, Data Breaches, AI and More

dnsmasq-discuss

[Dnsmasq-discuss] Announce: dnsmasq-2.92rc2 Re: [Dnsmasq-discuss] [PATCH] Fix arguments order for chaos subdomain check Re: [Dnsmasq-discuss] patch: block-file/allow-file - for review/feedback Re: [Dnsmasq-discuss] patch: block-file/allow-file - for review/feedback Re: [Dnsmasq-discuss] patch: block-file/allow-file - for review/feedback Re: [Dnsmasq-discuss] patch: block-file/allow-file - for review/feedback [Dnsmasq-discuss] patch: block-file/allow-file - for review/feedback Re: [Dnsmasq-discuss] server= with interface parameter changes behavior over time [Dnsmasq-discuss] NFTsets and hosts-files [Dnsmasq-discuss] [PATCH] Allow expired RRSIGs when stale caching is enabled [Dnsmasq-discuss] [PATCH] Fix local host records being overridden by upstream NXDOMAIN [Dnsmasq-discuss] [PATCH] Fix arguments order for chaos subdomain check Re: [Dnsmasq-discuss] Malformed RRSIG Can Crash dnsmasq [Dnsmasq-discuss] Malformed NSEC/NSEC3 Can Hang dnsmasq [Dnsmasq-discuss] Malformed RRSIG Can Crash dnsmasq [Dnsmasq-discuss] Security - IMPORTANT Re: [Dnsmasq-discuss] Issue with circuit-id matching on dhcp requests Re: [Dnsmasq-discuss] Issue with circuit-id matching on dhcp requests Re: [Dnsmasq-discuss] Issue with circuit-id matching on dhcp requests [Dnsmasq-discuss] Issue with circuit-id matching on dhcp requests Re: [Dnsmasq-discuss] [PATCH] bpf.c: fix memory leak in arp_enumerate() on BSD Re: [Dnsmasq-discuss] [PATCH] bpf.c: fix memory leak in arp_enumerate() on BSD Re: [Dnsmasq-discuss] dnssec problem here and now Re: [Dnsmasq-discuss] dnssec problem here and now [Dnsmasq-discuss] dnssec problem here and now Re: [Dnsmasq-discuss] server= with interface parameter changes behavior over time Re: [Dnsmasq-discuss] [PATCH] bpf.c: fix memory leak in arp_enumerate() on BSD Re: [Dnsmasq-discuss] [PATCH] bpf.c: fix memory leak in arp_enumerate() on BSD Re: [Dnsmasq-discuss] [PATCH] Preserve existing log file permissions when adding group-write bit. [Dnsmasq-discuss] server= with interface parameter changes behavior over time
[Dnsmasq-discuss] [PATCH] dnsmasq: failed to create inoti...
Petr Menšík via Dnsmasq-discuss · 2026-02-12 · via dnsmasq-discuss
Hello!

I have recently started to have issues when starting libvirt, which starts dnsmasq for DHCP and local machine DNS.

I have started seeing inotify sockets failures in multiple packages. But the thing is, I cannot start libvirt network now. I think inotify socket should not usually be cause of fatal error.

sudo virsh net-start default ends always with this failure. It usually helps to reboot the machine. I am not sure how to identify inotify usage on my machine.

Strange is this seems to be problem only of root user.

$ sudo inotifywatch /etc/resolv.conf
Establishing watches...
Failed to watch /etc/resolv.conf; upper limit on inotify watches reached!

$ inotifywatch /etc/resolv.conf
Establishing watches...
Finished establishing watches, now collecting statistics.

Strange is number of user watches should be somehow high:

$ cat /proc/sys/fs/inotify/max_user_watches
511013

So I started thinking, should be a failure to initialize inotify socket a fatal error? It seems to me warning would be all right.

dnsmasq supports running even without inotify support. I have created a modification to run even in that case, only emit warning. I think failure to observe resolv.conf changes should not be a fatal error, unless requested somehow more explicitly.

In attached change, I retry inotify creation with dropped privileges. It might help in my case and even for others. First time it fails only silently, because logging is not yet prepared. Only second time it also logs warnings.

Minor change is making more obvious difference between main inotify socket and inotify watch creation error.

Regards,
Petr

--
Petr Menšík
Senior Software Engineer, RHEL
Red Hat, https://www.redhat.com/
PGP: DFCF908DB7C87E8E529925BC4931CA5B6C9FC5CB
From 3c65be1c4e9aa31bdd5447bc633c1cd5474e9633 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <[email protected]>
Date: Wed, 11 Feb 2026 22:02:48 +0100
Subject: [PATCH] Make inotify initialization non-fatal error
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When inotify watch creation is not successful, print only warning. Retry
after dropping privileges because that might help too. Log warning only
the second time, when logging is properly initialized.

Signed-off-by: Petr Menšík <[email protected]>
---
 src/dnsmasq.c | 13 +++++++++++--
 src/dnsmasq.h |  2 +-
 src/inotify.c | 22 ++++++++++++++++------
 3 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/src/dnsmasq.c b/src/dnsmasq.c
index 7dbefc4c..0f46eb98 100644
--- a/src/dnsmasq.c
+++ b/src/dnsmasq.c
@@ -440,7 +440,7 @@ int main (int argc, char **argv)
 #ifdef HAVE_INOTIFY
   if ((daemon->port != 0 && !option_bool(OPT_NO_RESOLV)) ||
       daemon->dynamic_dirs)
-    inotify_dnsmasq_init();
+    inotify_dnsmasq_init(0);
   else
     daemon->inotifyfd = -1;
 #endif
@@ -864,6 +864,15 @@ int main (int argc, char **argv)
     }
 #endif
 
+#ifdef HAVE_INOTIFY
+  /* inotify creation failed for the root user.
+   * Retry with unprivileged user, log warnings this time. */
+  if (daemon->inotifyfd == -1 &&
+      ((daemon->port != 0 && !option_bool(OPT_NO_RESOLV)) ||
+       daemon->dynamic_dirs))
+    inotify_dnsmasq_init(1);
+#endif
+
    /* Don't start logging malloc before logging is set up. */
   daemon->log_malloc = option_bool(OPT_LOG_MALLOC);
   
@@ -1295,7 +1304,7 @@ int main (int argc, char **argv)
 	  check_ubus_listeners();
 	}
 #endif
-      
+
       if (daemon->port != 0)
 	check_dns_listeners(now);
 
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 1c001a83..d0990107 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -1905,7 +1905,7 @@ int detect_loop(char *query, int type);
 
 /* inotify.c */
 #ifdef HAVE_INOTIFY
-void inotify_dnsmasq_init(void);
+void inotify_dnsmasq_init(int log_warn);
 int inotify_check(time_t now);
 void set_dynamic_inotify(int flag, int total_size, struct crec **rhash, int revhashsz);
 #endif
diff --git a/src/inotify.c b/src/inotify.c
index f70daead..d01b416c 100644
--- a/src/inotify.c
+++ b/src/inotify.c
@@ -85,18 +85,22 @@ static char *my_readlink(char *path)
     }
 }
 
-void inotify_dnsmasq_init()
+void inotify_dnsmasq_init(int log_warn)
 {
   struct resolvc *res;
   inotify_buffer = safe_malloc(INOTIFY_SZ);
   daemon->inotifyfd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
-  
+
   if (daemon->inotifyfd == -1)
-    die(_("failed to create inotify: %s"), NULL, EC_MISC);
+    {
+      if (log_warn)
+        my_syslog(LOG_WARNING, _("failed to create inotify: %s"), strerror(errno));
+      return;
+    }
 
   if (daemon->port == 0 || option_bool(OPT_NO_RESOLV))
     return;
-  
+
   for (res = daemon->resolv_files; res; res = res->next)
     {
       char *d, *new_path, *path = safe_malloc(strlen(res->name) + 1);
@@ -127,8 +131,14 @@ void inotify_dnsmasq_init()
 	    die(_("directory %s for resolv-file is missing, cannot poll"), res->name, EC_MISC);
 	}	  
 	 
-      if (res->wd == -1)
-	die(_("failed to create inotify for %s: %s"), res->name, EC_MISC);
+      if (res->wd == -1) {
+	free(path);
+	if (log_warn)
+	  my_syslog(LOG_WARNING, _("failed to create inotify watch for %s: %s"), res->name, strerror(errno));
+	close(daemon->inotifyfd);
+	daemon->inotifyfd = -1;
+	return;
+      }
 	
     }
 }
-- 
2.53.0

_______________________________________________
Dnsmasq-discuss mailing list
[email protected]
https://lists.thekelleys.org.uk/cgi-bin/mailman/listinfo/dnsmasq-discuss