mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-20 02:38:32 +00:00
Teach the new inotify code about symlinks.
This commit is contained in:
@@ -41,6 +41,7 @@ void inotify_dnsmasq_init()
|
|||||||
|
|
||||||
inotify_buffer = safe_malloc(INOTIFY_SZ);
|
inotify_buffer = safe_malloc(INOTIFY_SZ);
|
||||||
|
|
||||||
|
|
||||||
daemon->inotifyfd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
|
daemon->inotifyfd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
|
||||||
|
|
||||||
if (daemon->inotifyfd == -1)
|
if (daemon->inotifyfd == -1)
|
||||||
@@ -48,24 +49,34 @@ void inotify_dnsmasq_init()
|
|||||||
|
|
||||||
for (res = daemon->resolv_files; res; res = res->next)
|
for (res = daemon->resolv_files; res; res = res->next)
|
||||||
{
|
{
|
||||||
char *d = strrchr(res->name, '/');
|
char *d = NULL, *path;
|
||||||
|
|
||||||
if (!d)
|
if (!(path = realpath(res->name, NULL)))
|
||||||
die(_("resolv-file %s not an absolute path"), res->name, EC_MISC);
|
{
|
||||||
|
/* realpath will fail if the file doesn't exist, but
|
||||||
|
dnsmasq copes with missing files, so fall back
|
||||||
|
and assume that symlinks are not in use in that case. */
|
||||||
|
if (errno == ENOENT)
|
||||||
|
path = res->name;
|
||||||
|
else
|
||||||
|
die(_("cannot cannonicalise resolv-file %s: %s"), res->name, EC_MISC);
|
||||||
|
}
|
||||||
|
|
||||||
*d = 0; /* make ->name just directory */
|
if ((d = strrchr(path, '/')))
|
||||||
res->wd = inotify_add_watch(daemon->inotifyfd, res->name, IN_CLOSE_WRITE | IN_MOVED_TO);
|
{
|
||||||
|
*d = 0; /* make path just directory */
|
||||||
|
res->wd = inotify_add_watch(daemon->inotifyfd, path, IN_CLOSE_WRITE | IN_MOVED_TO);
|
||||||
res->file = d+1; /* pointer to filename */
|
res->file = d+1; /* pointer to filename */
|
||||||
|
*d = '/';
|
||||||
|
|
||||||
if (res->wd == -1 && errno == ENOENT)
|
if (res->wd == -1 && errno == ENOENT)
|
||||||
die(_("directory %s for resolv-file is missing, cannot poll"), res->name, EC_MISC);
|
die(_("directory %s for resolv-file is missing, cannot poll"), res->name, EC_MISC);
|
||||||
|
|
||||||
*d = '/'; /* restore name */
|
|
||||||
|
|
||||||
if (res->wd == -1)
|
if (res->wd == -1)
|
||||||
die(_("failed to create inotify for %s: %s"), res->name, EC_MISC);
|
die(_("failed to create inotify for %s: %s"), res->name, EC_MISC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int inotify_check(void)
|
int inotify_check(void)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user