1 From 857973e6f7e0a3d03535a9df7f9373fd7a0b65cc Mon Sep 17 00:00:00 2001
2 From: Simon Kelley <simon@thekelleys.org.uk>
3 Date: Mon, 15 Dec 2014 15:58:13 +0000
4 Subject: [PATCH 010/113] Teach the new inotify code about symlinks.
7 src/inotify.c | 43 +++++++++++++++++++++++++++----------------
8 1 file changed, 27 insertions(+), 16 deletions(-)
10 diff --git a/src/inotify.c b/src/inotify.c
11 index a0223443d6b6..960bf5efb41f 100644
14 @@ -41,29 +41,40 @@ void inotify_dnsmasq_init()
16 inotify_buffer = safe_malloc(INOTIFY_SZ);
18 - daemon->inotifyfd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
20 + daemon->inotifyfd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
22 if (daemon->inotifyfd == -1)
23 die(_("failed to create inotify: %s"), NULL, EC_MISC);
26 for (res = daemon->resolv_files; res; res = res->next)
28 - char *d = strrchr(res->name, '/');
31 - die(_("resolv-file %s not an absolute path"), res->name, EC_MISC);
33 - *d = 0; /* make ->name just directory */
34 - res->wd = inotify_add_watch(daemon->inotifyfd, res->name, IN_CLOSE_WRITE | IN_MOVED_TO);
35 - res->file = d+1; /* pointer to filename */
37 - if (res->wd == -1 && errno == ENOENT)
38 - die(_("directory %s for resolv-file is missing, cannot poll"), res->name, EC_MISC);
39 + char *d = NULL, *path;
41 - *d = '/'; /* restore name */
42 + if (!(path = realpath(res->name, NULL)))
44 + /* realpath will fail if the file doesn't exist, but
45 + dnsmasq copes with missing files, so fall back
46 + and assume that symlinks are not in use in that case. */
47 + if (errno == ENOENT)
50 + die(_("cannot cannonicalise resolv-file %s: %s"), res->name, EC_MISC);
54 - die(_("failed to create inotify for %s: %s"), res->name, EC_MISC);
55 + if ((d = strrchr(path, '/')))
57 + *d = 0; /* make path just directory */
58 + res->wd = inotify_add_watch(daemon->inotifyfd, path, IN_CLOSE_WRITE | IN_MOVED_TO);
59 + res->file = d+1; /* pointer to filename */
62 + if (res->wd == -1 && errno == ENOENT)
63 + die(_("directory %s for resolv-file is missing, cannot poll"), res->name, EC_MISC);
66 + die(_("failed to create inotify for %s: %s"), res->name, EC_MISC);