Merge pull request #1732 from pi-hole/tweak/hosts_no_restart
Changing dns.hosts does not need a restart
This commit is contained in:
commit
a49c4c9cdd
|
@ -26,6 +26,8 @@
|
|||
#include "shmem.h"
|
||||
// hash_password()
|
||||
#include "config/password.h"
|
||||
// main_pid()
|
||||
#include "signals.h"
|
||||
|
||||
static struct {
|
||||
const char *name;
|
||||
|
@ -659,6 +661,7 @@ static int api_config_patch(struct ftl_conn *api)
|
|||
// Read all known config items
|
||||
bool config_changed = false;
|
||||
bool dnsmasq_changed = false;
|
||||
bool rewrite_hosts = false;
|
||||
struct config newconf;
|
||||
duplicate_config(&newconf, &config);
|
||||
for(unsigned int i = 0; i < CONFIG_ELEMENTS; i++)
|
||||
|
@ -730,6 +733,10 @@ static int api_config_patch(struct ftl_conn *api)
|
|||
if(conf_item->f & FLAG_RESTART_FTL)
|
||||
dnsmasq_changed = true;
|
||||
|
||||
// Check if this item requires rewriting the HOSTS file
|
||||
if(conf_item == &config.dns.hosts)
|
||||
rewrite_hosts = true;
|
||||
|
||||
// If the privacy level was decreased, we need to restart
|
||||
if(new_item == &newconf.misc.privacylevel &&
|
||||
new_item->v.privacy_level < conf_item->v.privacy_level)
|
||||
|
@ -768,6 +775,14 @@ static int api_config_patch(struct ftl_conn *api)
|
|||
|
||||
// Store changed configuration to disk
|
||||
writeFTLtoml(true);
|
||||
|
||||
// Rewrite HOSTS file if required
|
||||
if(rewrite_hosts)
|
||||
{
|
||||
write_custom_list();
|
||||
// Reload HOSTS file
|
||||
kill(main_pid(), SIGHUP);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -816,6 +831,7 @@ static int api_config_put_delete(struct ftl_conn *api)
|
|||
|
||||
// Read all known config items
|
||||
bool dnsmasq_changed = false;
|
||||
bool rewrite_hosts = false;
|
||||
bool found = false;
|
||||
struct config newconf;
|
||||
duplicate_config(&newconf, &config);
|
||||
|
@ -907,6 +923,10 @@ static int api_config_put_delete(struct ftl_conn *api)
|
|||
if(new_item->f & FLAG_RESTART_FTL)
|
||||
dnsmasq_changed = true;
|
||||
|
||||
// Check if this item requires rewriting the HOSTS file
|
||||
if(new_item == &newconf.dns.hosts)
|
||||
rewrite_hosts = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -954,6 +974,14 @@ static int api_config_put_delete(struct ftl_conn *api)
|
|||
// Store changed configuration to disk
|
||||
writeFTLtoml(true);
|
||||
|
||||
// Rewrite HOSTS file if required
|
||||
if(rewrite_hosts)
|
||||
{
|
||||
write_custom_list();
|
||||
// Reload HOSTS file
|
||||
kill(main_pid(), SIGHUP);
|
||||
}
|
||||
|
||||
// Send empty reply with matching HTTP status code
|
||||
// 201 - Created or 204 - No content
|
||||
cJSON *json = JSON_NEW_OBJECT();
|
||||
|
|
|
@ -462,7 +462,7 @@ void initConfig(struct config *conf)
|
|||
conf->dns.hosts.h = "Array of custom DNS records\n Example: hosts = [ \"127.0.0.1 mylocal\", \"192.168.0.1 therouter\" ]";
|
||||
conf->dns.hosts.a = cJSON_CreateStringReference("Array of custom DNS records each one in HOSTS form: \"IP HOSTNAME\"");
|
||||
conf->dns.hosts.t = CONF_JSON_STRING_ARRAY;
|
||||
conf->dns.hosts.f = FLAG_ADVANCED_SETTING | FLAG_RESTART_FTL;
|
||||
conf->dns.hosts.f = FLAG_ADVANCED_SETTING;
|
||||
conf->dns.hosts.d.json = cJSON_CreateArray();
|
||||
|
||||
conf->dns.domainNeeded.k = "dns.domainNeeded";
|
||||
|
|
|
@ -88,7 +88,7 @@ enum conf_type {
|
|||
#define FLAG_PSEUDO_ITEM (1 << 2)
|
||||
#define FLAG_INVALIDATE_SESSIONS (1 << 3)
|
||||
#define FLAG_WRITE_ONLY (1 << 4)
|
||||
#define FLAG_ENV_VAR (1 << 5)
|
||||
#define FLAG_ENV_VAR (1 << 5)
|
||||
|
||||
struct conf_item {
|
||||
const char *k; // item Key
|
||||
|
|
Loading…
Reference in New Issue