Skip to content
Snippets Groups Projects
Commit 2401c4e0 authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

Implemented zone refresh on SIGUSR2 signal.

refs #1833
parent 2bfe863d
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,7 @@
/* Signal flags. */
static volatile short sig_req_stop = 0;
static volatile short sig_req_reload = 0;
static volatile short sig_req_refresh = 0;
static volatile short sig_stopping = 0;
// SIGINT signal handler
......@@ -49,7 +50,13 @@ void interrupt_handle(int s)
sig_req_reload = 1;
return;
}
// Refresh
if (s == SIGUSR2) {
sig_req_refresh = 1;
return;
}
// Stop server
if (s == SIGINT || s == SIGTERM) {
if (sig_stopping == 0) {
......@@ -288,6 +295,7 @@ int main(int argc, char **argv)
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGHUP, &sa, NULL);
sigaction(SIGPIPE, &sa, NULL);
sigaction(SIGUSR2, &sa, NULL);
sa.sa_flags = 0;
pthread_sigmask(SIG_BLOCK, &sa.sa_mask, NULL);
......@@ -324,6 +332,17 @@ int main(int argc, char **argv)
break;
}
}
if (sig_req_refresh) {
log_server_info("Refreshing slave zones...\n");
sig_req_reload = 0;
int cf_ret = server_refresh(server);
if (cf_ret != KNOTD_EOK) {
log_server_error("Couldn't refresh "
"slave zones - %s",
knotd_strerror(cf_ret));
}
}
/* Events. */
if (ret > 0) {
......
......@@ -24,17 +24,20 @@
#include <assert.h>
#include <grp.h>
#include "common/prng.h"
#include "knot/common.h"
#include "knot/other/error.h"
#include "knot/server/server.h"
#include "knot/server/udp-handler.h"
#include "knot/server/tcp-handler.h"
#include "knot/server/xfr-handler.h"
#include "libknot/nameserver/name-server.h"
#include "knot/server/zones.h"
#include "knot/conf/conf.h"
#include "knot/stat/stat.h"
#include "libknot/nameserver/name-server.h"
#include "libknot/zone/zonedb.h"
#include "libknot/dname.h"
#include "knot/conf/conf.h"
/*! \brief Event scheduler loop. */
static int evsched_run(dthread_t *thread)
......@@ -610,6 +613,42 @@ int server_wait(server_t *server)
return ret;
}
int server_refresh(server_t *server)
{
if (server == NULL || server->nameserver == NULL) {
return KNOTD_EINVAL;
}
/* Lock RCU and fetch zones. */
rcu_read_lock();
knot_nameserver_t *ns = server->nameserver;
evsched_t *sch = ((server_t *)knot_ns_get_data(ns))->sched;
const knot_zone_t **zones = knot_zonedb_zones(ns->zone_db);
if (zones == NULL) {
rcu_read_unlock();
return KNOTD_ENOMEM;
}
/* REFRESH zones. */
for (unsigned i = 0; i < knot_zonedb_zone_count(ns->zone_db); ++i) {
zonedata_t *zd = (zonedata_t *)zones[i]->data;
if (zd == NULL) {
continue;
}
/* Expire REFRESH timer. */
if (zd->xfr_in.timer) {
evsched_cancel(sch, zd->xfr_in.timer);
evsched_schedule(sch, zd->xfr_in.timer,
tls_rand() * 1000);
}
}
/* Unlock RCU. */
rcu_read_unlock();
free(zones);
return KNOTD_EOK;
}
void server_stop(server_t *server)
{
dbg_server("server: stopping server\n");
......
......@@ -178,6 +178,16 @@ int server_start(server_t *server);
*/
int server_wait(server_t *server);
/*!
* \brief Refresh served zones.
*
* \param server Server structure to be used for operation.
*
* \retval 0 On success (EOK).
* \retval <0 If an error occured (EINVAL).
*/
int server_refresh(server_t *server);
/*!
* \brief Requests server to stop.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment