[Dnsmasq-discuss] Inotify code & older linux

Kevin Darbyshire-Bryant kevin at darbyshire-bryant.me.uk
Thu Jan 22 09:09:29 GMT 2015


Hi Simon

I'm wondering if you'd consider putting the new 'inotify' related code
as a compile time option please.  Unfortunately there are a few router
based projects that rely on old kernels without inotify support.  I've
included a patch that I've hopefully generated & coded correctly that
wraps the inotify related code into 'HAVE_INOTIFY' blocks.  It probably
requires some sanity checking on my behalf.  Thanks for your time.

Kevin

diff --git a/src/config.h b/src/config.h
index aa0c21f..831c537 100644
--- a/src/config.h
+++ b/src/config.h
@@ -119,6 +119,8 @@ HAVE_DNSSEC
 HAVE_LOOP
    include functionality to probe for and remove DNS forwarding loops.
 
+HAVE_INOTIFY
+   use inotify instead of polling on linux
 
 NO_IPV6
 NO_TFTP
@@ -161,6 +163,7 @@ RESOLVFILE
 #define HAVE_AUTH
 #define HAVE_IPSET
 #define HAVE_LOOP
+#define HAVE_INOTIFY
 
 /* Build options which require external libraries.
   
@@ -363,6 +366,10 @@ HAVE_SOCKADDR_SA_LEN
 #define HAVE_LEASEFILE_EXPIRE
 #endif
 
+#if defined(NO_INOTIFY) || !defined(HAVE_LINUX_NETWORK)
+#undef HAVE_INOTIFY
+#endif
+
 /* Define a string indicating which options are in use.
    DNSMASQP_COMPILE_OPTS is only defined in dnsmasq.c */
 
diff --git a/src/dnsmasq.c b/src/dnsmasq.c
index 127ef8d..73e3139 100644
--- a/src/dnsmasq.c
+++ b/src/dnsmasq.c
@@ -359,7 +359,7 @@ int main (int argc, char **argv)
 #endif
     }
 
-#ifdef HAVE_LINUX_NETWORK
+#ifdef HAVE_INOTIFY
   if ((!option_bool(OPT_NO_POLL) && daemon->port != 0) ||
       daemon->dhcp || daemon->doing_dhcp6)
     inotify_dnsmasq_init();
@@ -909,11 +909,13 @@ int main (int argc, char **argv)
 #if defined(HAVE_LINUX_NETWORK)
       FD_SET(daemon->netlinkfd, &rset);
       bump_maxfd(daemon->netlinkfd, &maxfd);
+#ifdef HAVE_INOTIFY
       if (daemon->inotifyfd != -1)
     {
       FD_SET(daemon->inotifyfd, &rset);
       bump_maxfd(daemon->inotifyfd, &maxfd);
     }
+#endif
 #elif defined(HAVE_BSD_NETWORK)
       FD_SET(daemon->routefd, &rset);
       bump_maxfd(daemon->routefd, &maxfd);
@@ -981,8 +983,8 @@ int main (int argc, char **argv)
     route_sock();
 #endif
 
-#ifdef HAVE_LINUX_NETWORK
-      if  (daemon->inotifyfd != -1 && FD_ISSET(daemon->inotifyfd,
&rset) && inotify_check(now))
+#ifdef HAVE_INOTIFY
+  if  (daemon->inotifyfd != -1 && FD_ISSET(daemon->inotifyfd, &rset) &&
inotify_check(now))
     {
       if (daemon->port != 0 && !option_bool(OPT_NO_POLL))
         poll_resolv(1, 1, now);
@@ -1003,6 +1005,7 @@ int main (int argc, char **argv)
      
       if (FD_ISSET(piperead, &rset))
     async_event(piperead, now);
+#endif
      
 #ifdef HAVE_DBUS
       /* if we didn't create a DBus connection, retry now. */
@@ -1446,7 +1449,7 @@ void clear_cache_and_reload(time_t now)
       if (option_bool(OPT_ETHERS))
     dhcp_read_ethers();
       reread_dhcp();
-#ifdef HAVE_LINUX_NETWORK
+#ifdef HAVE_INOTIFY
       set_dhcp_inotify();
 #endif
       dhcp_update_configs(daemon->dhcp_conf);
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index bbda8ff..2755fc5 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -554,7 +554,7 @@ struct hostsfile {
   struct hostsfile *next;
   int flags;
   char *fname;
-#ifdef HAVE_LINUX_NETWORK
+#ifdef HAVE_INOTIFY
   int wd; /* inotify watch descriptor */
 #endif
   unsigned int index; /* matches to cache entries for logging */
@@ -1011,6 +1011,9 @@ extern struct daemon {
   int dhcpfd, helperfd, pxefd;
 #if defined(HAVE_LINUX_NETWORK)
   int netlinkfd;
+#if defined(HAVE_INOTIFY)
+  int inotifyfd;
+#endif
 #elif defined(HAVE_BSD_NETWORK)
   int dhcp_raw_fd, dhcp_icmp_fd, routefd;
 #endif
@@ -1492,7 +1495,7 @@ int detect_loop(char *query, int type);
 #endif
 
 /* inotify.c */
-#ifdef HAVE_LINUX_NETWORK
+#ifdef HAVE_INOTIFY
 void inotify_dnsmasq_init();
 int inotify_check(time_t now);
 #  ifdef HAVE_DHCP
diff --git a/src/inotify.c b/src/inotify.c
index 52a30d7..818fe8e 100644
--- a/src/inotify.c
+++ b/src/inotify.c
@@ -15,7 +15,7 @@
 */
 
 #include "dnsmasq.h"
-#ifdef HAVE_LINUX_NETWORK
+#ifdef HAVE_INOTIFY
 
 #include <sys/inotify.h>
 
@@ -216,5 +216,5 @@ static void check_for_dhcp_inotify(struct
inotify_event *in, time_t now)
 
 #endif /* DHCP */
 
-#endif  /* LINUX_NETWORK */
+#endif  /* INOTIFY */
  






-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4791 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20150122/d352b563/attachment-0001.bin>


More information about the Dnsmasq-discuss mailing list