[PATCH v2 2/3] virdnsmasq: Lookup DNSMASQ in PATH

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



While it's true that our virCommand subsystem is happy with
non-absolute paths, the dnsmasq capability code is not. For
instance, it does call stat() over the binary to learn its mtime
(and thus decide whether capabilities need to be fetched again or
not).

Therefore, when constructing the capabilities structure look up
the binary path. If DNSMASQ already contains an absolute path
then virFindFileInPath() will simply return a copy. But, if we
failed to find the binary in $PATH then do not report error.
Either the dnsmasqCapsNewEmpty() function is called from
dnsmasqCapsNewFromBinary() which will later validate the path and
return appropriate error, or the function is called from a test
suite (via dnsmasqCapsNewFromBuffer()) and the caps are parsed
from a fixed string.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
Diff to v1:
- Per my experiments we need a fallback case when DNSMASQ exists but is
  not executable.

At any rate, this whole code could use cleanup, but let's save that for
after the release.

 src/util/virdnsmasq.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c
index d304929d51..8ddc2d0b78 100644
--- a/src/util/virdnsmasq.c
+++ b/src/util/virdnsmasq.c
@@ -703,12 +703,21 @@ static dnsmasqCaps *
 dnsmasqCapsNewEmpty(void)
 {
     dnsmasqCaps *caps;
+    g_autofree char *binaryPath = NULL;
 
     if (dnsmasqCapsInitialize() < 0)
         return NULL;
     if (!(caps = virObjectNew(dnsmasqCapsClass)))
         return NULL;
-    caps->binaryPath = g_strdup(DNSMASQ);
+
+    if (!(binaryPath = virFindFileInPath(DNSMASQ))) {
+        /* Don't report error here because we might be running
+         * from a test suite an initializing capabilities from
+         * a buffer (dnsmasqCapsNewFromBuffer()). */
+        binaryPath = g_strdup(DNSMASQ);
+    }
+
+    caps->binaryPath = g_steal_pointer(&binaryPath);
     return caps;
 }
 
-- 
2.34.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux