[libvirt] [PATCH v2 10/37] Adapt to VIR_STRDUP in src/lxc/*

Michal Privoznik mprivozn at redhat.com
Mon Apr 29 13:50:32 UTC 2013


---
 src/lxc/lxc_cgroup.c     |  2 +-
 src/lxc/lxc_conf.c       | 18 +++++++++---------
 src/lxc/lxc_container.c  |  8 ++++----
 src/lxc/lxc_controller.c |  6 +++---
 src/lxc/lxc_driver.c     |  7 ++-----
 src/lxc/lxc_process.c    |  4 ++--
 6 files changed, 21 insertions(+), 24 deletions(-)

diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index bc3b0d1..2df8ba8 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -538,7 +538,7 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, bool startup)
             goto cleanup;
         }
 
-        if (!(res->partition = strdup("/machine"))) {
+        if (VIR_STRDUP(res->partition, "/machine") < 0) {
             virReportOOMError();
             VIR_FREE(res);
             goto cleanup;
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index 13c0d97..2971c08 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -37,7 +37,7 @@
 #include "configmake.h"
 #include "lxc_container.h"
 #include "virnodesuspend.h"
-
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_LXC
 
@@ -119,9 +119,9 @@ virCapsPtr lxcCapsInit(virLXCDriverPtr driver)
             if (VIR_ALLOC(caps->host.secModels) < 0)
                 goto no_memory;
             caps->host.nsecModels = 1;
-            if (!(caps->host.secModels[0].model = strdup(model)))
+            if (VIR_STRDUP(caps->host.secModels[0].model, model) < 0)
                 goto no_memory;
-            if (!(caps->host.secModels[0].doi = strdup(doi)))
+            if (VIR_STRDUP(caps->host.secModels[0].doi, doi) < 0)
                 goto no_memory;
         }
 
@@ -161,17 +161,17 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver)
     driver->securityRequireConfined = false;
 
     /* Set the container configuration directory */
-    if ((driver->configDir = strdup(LXC_CONFIG_DIR)) == NULL)
+    if (VIR_STRDUP(driver->configDir,LXC_CONFIG_DIR) < 0)
         goto no_memory;
-    if ((driver->stateDir = strdup(LXC_STATE_DIR)) == NULL)
+    if (VIR_STRDUP(driver->stateDir, LXC_STATE_DIR) < 0)
         goto no_memory;
-    if ((driver->logDir = strdup(LXC_LOG_DIR)) == NULL)
+    if (VIR_STRDUP(driver->logDir, LXC_LOG_DIR) < 0)
         goto no_memory;
-    if ((driver->autostartDir = strdup(LXC_AUTOSTART_DIR)) == NULL)
+    if (VIR_STRDUP(driver->autostartDir, LXC_AUTOSTART_DIR) < 0)
         goto no_memory;
 
 
-    if ((filename = strdup(SYSCONFDIR "/libvirt/lxc.conf")) == NULL)
+    if (VIR_STRDUP(filename, SYSCONFDIR "/libvirt/lxc.conf") < 0)
         goto no_memory;
 
     /* Avoid error from non-existant or unreadable file. */
@@ -196,7 +196,7 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver)
     p = virConfGetValue(conf, "security_driver");
     CHECK_TYPE("security_driver", VIR_CONF_STRING);
     if (p && p->str) {
-        if (!(driver->securityDriverName = strdup(p->str))) {
+        if (VIR_STRDUP(driver->securityDriverName, p->str) < 0) {
             virReportOOMError();
             virConfFree(conf);
             return -1;
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index ff4069a..6bf9916 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -439,7 +439,7 @@ static int lxcContainerGetSubtree(const char *prefix,
             virReportOOMError();
             goto cleanup;
         }
-        if (!(mounts[nmounts] = strdup(mntent.mnt_dir))) {
+        if (VIR_STRDUP(mounts[nmounts], mntent.mnt_dir) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -1041,7 +1041,7 @@ lxcContainerMountDetectFilesystem(const char *src, char **type)
         goto cleanup;
     }
 
-    if (!(*type = strdup(data))) {
+    if (VIR_STRDUP(*type, data) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -1948,13 +1948,13 @@ static int lxcContainerChild(void *data)
                 goto cleanup;
             }
         } else {
-            if (!(ttyPath = strdup(argv->ttyPaths[0]))) {
+            if (VIR_STRDUP(ttyPath, argv->ttyPaths[0]) < 0) {
                 virReportOOMError();
                 goto cleanup;
             }
         }
     } else {
-        if (!(ttyPath = strdup("/dev/null"))) {
+        if (VIR_STRDUP(ttyPath, "/dev/null") < 0) {
             virReportOOMError();
             goto cleanup;
         }
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index f1800eb..855a6d1 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -156,7 +156,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name)
     ctrl->timerShutdown = -1;
     ctrl->firstClient = true;
 
-    if (!(ctrl->name = strdup(name)))
+    if (VIR_STRDUP(ctrl->name, name) < 0)
         goto no_memory;
 
     if ((caps = lxcCapsInit(NULL)) == NULL)
@@ -1566,7 +1566,7 @@ int main(int argc, char *argv[])
             break;
 
         case 'n':
-            if ((name = strdup(optarg)) == NULL) {
+            if (VIR_STRDUP(name, optarg) < 0) {
                 virReportOOMError();
                 goto cleanup;
             }
@@ -1577,7 +1577,7 @@ int main(int argc, char *argv[])
                 virReportOOMError();
                 goto cleanup;
             }
-            if ((veths[nveths++] = strdup(optarg)) == NULL) {
+            if (VIR_STRDUP(veths[nveths++], optarg) < 0) {
                 virReportOOMError();
                 goto cleanup;
             }
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 84a97de..3a1bbbf 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -626,9 +626,7 @@ static char *lxcDomainGetOSType(virDomainPtr dom)
         goto cleanup;
     }
 
-    ret = strdup(vm->def->os.type);
-
-    if (ret == NULL)
+    if (VIR_STRDUP(ret, vm->def->os.type) < 0)
         virReportOOMError();
 
 cleanup:
@@ -1629,8 +1627,7 @@ static char *lxcDomainGetSchedulerType(virDomainPtr dom,
             *nparams = 3;
     }
 
-    ret = strdup("posix");
-    if (!ret)
+    if (VIR_STRDUP(ret, "posix") < 0)
         virReportOOMError();
 
 cleanup:
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index b10e81c..5c36fae 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -996,8 +996,8 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm)
 
     root->type = VIR_DOMAIN_FS_TYPE_MOUNT;
 
-    if (!(root->src = strdup("/")) ||
-        !(root->dst = strdup("/")))
+    if (VIR_STRDUP(root->src, "/") < 0 ||
+        VIR_STRDUP(root->dst, "/") < 0)
         goto no_memory;
 
     if (VIR_INSERT_ELEMENT(vm->def->fss,
-- 
1.8.1.5




More information about the libvir-list mailing list