privops: separate res_init() call
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.
This commit is contained in:
parent
5187c08c90
commit
6db8ec1ba2
4 changed files with 52 additions and 4 deletions
2
configure
vendored
2
configure
vendored
|
@ -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
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
45
privops.c
45
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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue