]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
privops: separate res_init() call
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 7 Mar 2017 15:43:33 +0000 (16:43 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 10 Mar 2017 15:51:02 +0000 (16:51 +0100)
Move the res_init() call from do_name_to_ipaddress() into a separate
privops operation. Use it in ntp_sources and avoid unnecessary
res_init() calls in the main thread.

configure
ntp_sources.c
privops.c
privops.h

index b4a33c3370bd7106b40f5c9aff9bd895d6effb02..6a32a3fde26692360fa14897adb18109a731371e 100755 (executable)
--- a/configure
+++ b/configure
@@ -709,7 +709,7 @@ then
   # NAME2IPADDRESS shouldn't be enabled with other operations as the helper
   # process works on one request at the time and the async resolver could
   # block the main thread
-  priv_ops="NAME2IPADDRESS"
+  priv_ops="NAME2IPADDRESS RELOADDNS"
   EXTRA_LIBS="$EXTRA_LIBS -lseccomp"
 fi
 
index 5024a423e441383dab0d8aedc16b26f26b96cb72..506f4b0cfe5e0a98eabfeadae700469e3098ece1 100644 (file)
@@ -39,6 +39,7 @@
 #include "local.h"
 #include "memory.h"
 #include "nameserv_async.h"
+#include "privops.h"
 #include "sched.h"
 
 /* ================================================== */
@@ -469,7 +470,7 @@ resolve_sources(void *arg)
 
   assert(!resolving_source);
 
-  DNS_Reload();
+  PRV_ReloadDNS();
 
   /* Start with the first source in the list, name_resolve_handler
      will iterate over the rest */
index b5881314f3baeee84d20bb1e2d57c0708ef7237d..ca2639bb7ef57596a138263fa92e2cb95b80f970 100644 (file)
--- a/privops.c
+++ b/privops.c
@@ -40,6 +40,7 @@
 #define OP_SETTIME        1026
 #define OP_BINDSOCKET     1027
 #define OP_NAME2IPADDRESS 1028
+#define OP_RELOADDNS      1029
 #define OP_QUIT           1099
 
 union sockaddr_in46 {
@@ -293,8 +294,6 @@ do_name_to_ipaddress(ReqName2IPAddress *req, PrvResponse *res)
   /* make sure the string is terminated */
   req->name[sizeof (req->name) - 1] = '\0';
 
-  DNS_Reload();
-
   res->rc = DNS_Name2IPAddress(req->name, res->data.name_to_ipaddress.addresses,
                                DNS_MAX_ADDRESSES);
 }
@@ -302,6 +301,19 @@ do_name_to_ipaddress(ReqName2IPAddress *req, PrvResponse *res)
 
 /* ======================================================================= */
 
+/* HELPER - perform DNS_Reload() */
+
+#ifdef PRIVOPS_RELOADDNS
+static void
+do_reload_dns(PrvResponse *res)
+{
+  DNS_Reload();
+  res->rc = 0;
+}
+#endif
+
+/* ======================================================================= */
+
 /* HELPER - main loop - action requests from the daemon */
 
 static void
@@ -343,6 +355,11 @@ helper_main(int fd)
       case OP_NAME2IPADDRESS:
         do_name_to_ipaddress(&req.data.name_to_ipaddress, &res);
         break;
+#endif
+#ifdef PRIVOPS_RELOADDNS
+      case OP_RELOADDNS:
+        do_reload_dns(&res);
+        break;
 #endif
       case OP_QUIT:
         quit = 1;
@@ -613,6 +630,30 @@ PRV_Name2IPAddress(const char *name, IPAddr *ip_addrs, int max_addrs)
 
 /* ======================================================================= */
 
+/* DAEMON - request res_init() */
+
+#ifdef PRIVOPS_RELOADDNS
+void
+PRV_ReloadDNS(void)
+{
+  PrvRequest req;
+  PrvResponse res;
+
+  if (!have_helper()) {
+    DNS_Reload();
+    return;
+  }
+
+  memset(&req, 0, sizeof (req));
+  req.op = OP_RELOADDNS;
+
+  submit_request(&req, &res);
+  assert(!res.rc);
+}
+#endif
+
+/* ======================================================================= */
+
 void
 PRV_Initialise(void)
 {
index 77cdde70b1cfed5bfec030d1bf81579248937740..146580b7f9d0a0d335858dd3c4f88848adf10c39 100644 (file)
--- a/privops.h
+++ b/privops.h
@@ -58,6 +58,12 @@ int PRV_Name2IPAddress(const char *name, IPAddr *ip_addrs, int max_addrs);
 #define PRV_Name2IPAddress DNS_Name2IPAddress
 #endif
 
+#ifdef PRIVOPS_RELOADDNS
+void PRV_ReloadDNS(void);
+#else
+#define PRV_ReloadDNS DNS_Reload
+#endif
+
 #ifdef PRIVOPS_HELPER
 void PRV_Initialise(void);
 void PRV_StartHelper(void);