summaryrefslogtreecommitdiff
path: root/src/inotify.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/inotify.c')
-rw-r--r--src/inotify.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/inotify.c b/src/inotify.c
index 52d412f..7107833 100644
--- a/src/inotify.c
+++ b/src/inotify.c
@@ -1,4 +1,4 @@
-/* dnsmasq is Copyright (c) 2000-2015 Simon Kelley
+/* dnsmasq is Copyright (c) 2000-2018 Simon Kelley
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@
#include <sys/inotify.h>
#include <sys/param.h> /* For MAXSYMLINKS */
-/* the strategy is to set a inotify on the directories containing
+/* the strategy is to set an inotify on the directories containing
resolv files, for any files in the directory which are close-write
or moved into the directory.
@@ -54,7 +54,10 @@ static char *my_readlink(char *path)
{
/* Not link or doesn't exist. */
if (errno == EINVAL || errno == ENOENT)
- return NULL;
+ {
+ free(buf);
+ return NULL;
+ }
else
die(_("cannot access path %s: %s"), path, EC_MISC);
}
@@ -90,6 +93,9 @@ void inotify_dnsmasq_init()
if (daemon->inotifyfd == -1)
die(_("failed to create inotify: %s"), NULL, EC_MISC);
+
+ if (option_bool(OPT_NO_RESOLV))
+ return;
for (res = daemon->resolv_files; res; res = res->next)
{
@@ -98,7 +104,7 @@ void inotify_dnsmasq_init()
strcpy(path, res->name);
- /* Follow symlinks until we reach a non-symlink, or a non-existant file. */
+ /* Follow symlinks until we reach a non-symlink, or a non-existent file. */
while ((new_path = my_readlink(path)))
{
if (links-- == 0)
@@ -197,6 +203,8 @@ void set_dynamic_inotify(int flag, int total_size, struct crec **rhash, int revh
free(path);
}
}
+
+ closedir(dir_stream);
}
}
@@ -219,19 +227,21 @@ int inotify_check(time_t now)
for (p = inotify_buffer; rc - (p - inotify_buffer) >= (int)sizeof(struct inotify_event); p += sizeof(struct inotify_event) + in->len)
{
+ size_t namelen;
+
in = (struct inotify_event*)p;
- for (res = daemon->resolv_files; res; res = res->next)
- if (res->wd == in->wd && in->len != 0 && strcmp(res->file, in->name) == 0)
- hit = 1;
-
/* ignore emacs backups and dotfiles */
- if (in->len == 0 ||
- in->name[in->len - 1] == '~' ||
- (in->name[0] == '#' && in->name[in->len - 1] == '#') ||
+ if (in->len == 0 || (namelen = strlen(in->name)) == 0 ||
+ in->name[namelen - 1] == '~' ||
+ (in->name[0] == '#' && in->name[namelen - 1] == '#') ||
in->name[0] == '.')
continue;
-
+
+ for (res = daemon->resolv_files; res; res = res->next)
+ if (res->wd == in->wd && strcmp(res->file, in->name) == 0)
+ hit = 1;
+
for (ah = daemon->dynamic_dirs; ah; ah = ah->next)
if (ah->wd == in->wd)
{
@@ -252,7 +262,7 @@ int inotify_check(time_t now)
#ifdef HAVE_DHCP
if (daemon->dhcp || daemon->doing_dhcp6)
{
- /* Propogate the consequences of loading a new dhcp-host */
+ /* Propagate the consequences of loading a new dhcp-host */
dhcp_update_configs(daemon->dhcp_conf);
lease_update_from_configs();
lease_update_file(now);
@@ -265,7 +275,7 @@ int inotify_check(time_t now)
{
if (option_read_dynfile(path, AH_DHCP_HST))
{
- /* Propogate the consequences of loading a new dhcp-host */
+ /* Propagate the consequences of loading a new dhcp-host */
dhcp_update_configs(daemon->dhcp_conf);
lease_update_from_configs();
lease_update_file(now);