diff --git a/configure b/configure index b4a33c3..6a32a3f 100755 --- 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 diff --git a/ntp_sources.c b/ntp_sources.c index 5024a42..506f4b0 100644 --- a/ntp_sources.c +++ b/ntp_sources.c @@ -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 */ diff --git a/privops.c b/privops.c index b588131..ca2639b 100644 --- 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) { diff --git a/privops.h b/privops.h index 77cdde7..146580b 100644 --- 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);