]> git.ipfire.org Git - ipfire-2.x.git/blame - src/patches/dnsmasq/0010-Teach-the-new-inotify-code-about-symlinks.patch
dnsmasq: Import patches from upstream
[ipfire-2.x.git] / src / patches / dnsmasq / 0010-Teach-the-new-inotify-code-about-symlinks.patch
CommitLineData
6644c1c7
MT
1From 857973e6f7e0a3d03535a9df7f9373fd7a0b65cc Mon Sep 17 00:00:00 2001
2From: Simon Kelley <simon@thekelleys.org.uk>
3Date: Mon, 15 Dec 2014 15:58:13 +0000
efbd3a9a 4Subject: [PATCH 10/98] Teach the new inotify code about symlinks.
6644c1c7
MT
5
6---
7 src/inotify.c | 43 +++++++++++++++++++++++++++----------------
8 1 file changed, 27 insertions(+), 16 deletions(-)
9
10diff --git a/src/inotify.c b/src/inotify.c
11index a0223443d6b6..960bf5efb41f 100644
12--- a/src/inotify.c
13+++ b/src/inotify.c
14@@ -41,29 +41,40 @@ void inotify_dnsmasq_init()
15
16 inotify_buffer = safe_malloc(INOTIFY_SZ);
17
18- daemon->inotifyfd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
19
20+ daemon->inotifyfd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
21+
22 if (daemon->inotifyfd == -1)
23 die(_("failed to create inotify: %s"), NULL, EC_MISC);
24-
25+
26 for (res = daemon->resolv_files; res; res = res->next)
27 {
28- char *d = strrchr(res->name, '/');
29-
30- if (!d)
31- die(_("resolv-file %s not an absolute path"), res->name, EC_MISC);
32-
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 */
36-
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;
40
41- *d = '/'; /* restore name */
42+ if (!(path = realpath(res->name, NULL)))
43+ {
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)
48+ path = res->name;
49+ else
50+ die(_("cannot cannonicalise resolv-file %s: %s"), res->name, EC_MISC);
51+ }
52
53- if (res->wd == -1)
54- die(_("failed to create inotify for %s: %s"), res->name, EC_MISC);
55+ if ((d = strrchr(path, '/')))
56+ {
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 */
60+ *d = '/';
61+
62+ if (res->wd == -1 && errno == ENOENT)
63+ die(_("directory %s for resolv-file is missing, cannot poll"), res->name, EC_MISC);
64+
65+ if (res->wd == -1)
66+ die(_("failed to create inotify for %s: %s"), res->name, EC_MISC);
67+ }
68 }
69 }
70
71--
722.1.0
73