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

[libvirt] [PATCH 4/6] v1: get, parse, and save dnsmasq version id



Use "dnsmasq --version" to obtain dnsmasq's version id and
save the major/minor values.  This is a separate patch since other
patches will depend on it.
---
 src/conf/network_conf.h     |  2 ++
 src/network/bridge_driver.c | 35 +++++++++++++++++++++++++++++++++--
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 3e46304..cfc49af 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -218,6 +218,8 @@ struct _virNetworkObj {
     unsigned int active : 1;
     unsigned int autostart : 1;
     unsigned int persistent : 1;
+    unsigned int dnsmasqMajor;
+    unsigned int dnsmasqMinor;
 
     virNetworkDefPtr def; /* The current definition */
     virNetworkDefPtr newDef; /* New definition to activate at shutdown */
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 0c4c794..19610f2 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -968,21 +968,51 @@ cleanup:
     return ret;
 }
 
+#define DNSMASQ_VERSION_PREFIX "Dnsmasq version "
+
 static int
 networkStartDhcpDaemon(virNetworkObjPtr network)
 {
     virCommandPtr cmd = NULL;
+    const char *cmdname = DNSMASQ;
+    char *tmp, *version = NULL;
+    unsigned int  major = 0, minor = 0;
     char *pidfile = NULL;
     char *testconfigstr = NULL;
     int ret = -1;
     dnsmasqContext *dctx = NULL;
 
     if (!virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, 0)) {
-        /* no IPv6 addresses, so we don't need to run radvd */
+        /* no IP addresses, so we don't need to run */
         ret = 0;
         goto cleanup;
     }
-    VIR_INFO("starting dhcp daemon (dnsmasq)");
+
+    if (!virFileIsExecutable(cmdname)) {
+        VIR_WARN("file %s missing or not executable", cmdname);
+        goto cleanup;
+    }
+    VIR_INFO("starting dhcp daemon (%s)", cmdname);
+
+    cmd = virCommandNew(cmdname);
+    virCommandAddArg(cmd, "--version");
+    virCommandSetOutputBuffer(cmd, &version);
+    if (virCommandRun(cmd, NULL) < 0)
+        goto cleanup;
+    virCommandFree(cmd);
+    cmd = NULL;
+
+    if ((version!=NULL) &&
+        (strncmp(version, DNSMASQ_VERSION_PREFIX, strlen(DNSMASQ_VERSION_PREFIX))==0)) {
+        tmp = version + strlen(DNSMASQ_VERSION_PREFIX);
+        if (virStrToLong_ui(tmp, &tmp, 10, &major) >= 0) {
+            if ((*tmp == '.') &&
+                    virStrToLong_ui(tmp + 1, &tmp, 10, &minor) >= 0) {
+                network->dnsmasqMajor = major;
+                network->dnsmasqMinor = minor;
+            }
+        }
+    }
 
     if (virFileMakePath(NETWORK_PID_DIR) < 0) {
         virReportSystemError(errno,
@@ -1043,6 +1073,7 @@ networkStartDhcpDaemon(virNetworkObjPtr network)
     ret = 0;
 cleanup:
     VIR_FREE(pidfile);
+    VIR_FREE(version);
     virCommandFree(cmd);
     dnsmasqContextFree(dctx);
     return ret;
-- 
1.7.11.7


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