[libvirt] [PATCH v3 09/34] Adapt to VIR_STRDUP and VIR_STRNDUP in src/lxc/*

Michal Privoznik mprivozn at redhat.com
Fri May 3 14:53:14 UTC 2013


---
 src/lxc/lxc_cgroup.c     |  3 +--
 src/lxc/lxc_conf.c       | 36 +++++++++++++++++-------------------
 src/lxc/lxc_container.c  | 18 ++++--------------
 src/lxc/lxc_controller.c | 20 ++++++++------------
 src/lxc/lxc_driver.c     |  9 ++-------
 src/lxc/lxc_process.c    |  7 ++++---
 6 files changed, 36 insertions(+), 57 deletions(-)

diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index bc3b0d1..de6b53b 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -538,8 +538,7 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, bool startup)
             goto cleanup;
         }
 
-        if (!(res->partition = strdup("/machine"))) {
-            virReportOOMError();
+        if (VIR_STRDUP(res->partition, "/machine") < 0) {
             VIR_FREE(res);
             goto cleanup;
         }
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index 13c0d97..81a4a33 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,10 +119,10 @@ 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)))
-                goto no_memory;
-            if (!(caps->host.secModels[0].doi = strdup(doi)))
-                goto no_memory;
+            if (VIR_STRDUP(caps->host.secModels[0].model, model) < 0)
+                goto error;
+            if (VIR_STRDUP(caps->host.secModels[0].doi, doi) < 0)
+                goto error;
         }
 
         VIR_DEBUG("Initialized caps for security driver \"%s\" with "
@@ -161,18 +161,18 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver)
     driver->securityRequireConfined = false;
 
     /* Set the container configuration directory */
-    if ((driver->configDir = strdup(LXC_CONFIG_DIR)) == NULL)
-        goto no_memory;
-    if ((driver->stateDir = strdup(LXC_STATE_DIR)) == NULL)
-        goto no_memory;
-    if ((driver->logDir = strdup(LXC_LOG_DIR)) == NULL)
-        goto no_memory;
-    if ((driver->autostartDir = strdup(LXC_AUTOSTART_DIR)) == NULL)
-        goto no_memory;
+    if (VIR_STRDUP(driver->configDir, LXC_CONFIG_DIR) < 0)
+        goto error;
+    if (VIR_STRDUP(driver->stateDir, LXC_STATE_DIR) < 0)
+        goto error;
+    if (VIR_STRDUP(driver->logDir, LXC_LOG_DIR) < 0)
+        goto error;
+    if (VIR_STRDUP(driver->autostartDir, LXC_AUTOSTART_DIR) < 0)
+        goto error;
 
 
-    if ((filename = strdup(SYSCONFDIR "/libvirt/lxc.conf")) == NULL)
-        goto no_memory;
+    if (VIR_STRDUP(filename, SYSCONFDIR "/libvirt/lxc.conf") < 0)
+        goto error;
 
     /* Avoid error from non-existant or unreadable file. */
     if (access(filename, R_OK) == -1)
@@ -196,8 +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))) {
-            virReportOOMError();
+        if (VIR_STRDUP(driver->securityDriverName, p->str) < 0) {
             virConfFree(conf);
             return -1;
         }
@@ -220,7 +219,6 @@ done:
     VIR_FREE(filename);
     return 0;
 
-no_memory:
-    virReportOOMError();
+error:
     return -1;
 }
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index ff4069a..2ad0bcf 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -439,10 +439,8 @@ static int lxcContainerGetSubtree(const char *prefix,
             virReportOOMError();
             goto cleanup;
         }
-        if (!(mounts[nmounts] = strdup(mntent.mnt_dir))) {
-            virReportOOMError();
+        if (VIR_STRDUP(mounts[nmounts], mntent.mnt_dir) < 0)
             goto cleanup;
-        }
         nmounts++;
         VIR_DEBUG("Grabbed %s", mntent.mnt_dir);
     }
@@ -1041,10 +1039,8 @@ lxcContainerMountDetectFilesystem(const char *src, char **type)
         goto cleanup;
     }
 
-    if (!(*type = strdup(data))) {
-        virReportOOMError();
+    if (VIR_STRDUP(*type, data) < 0)
         goto cleanup;
-    }
 
 done:
     ret = 0;
@@ -1947,17 +1943,11 @@ static int lxcContainerChild(void *data)
                 virReportOOMError();
                 goto cleanup;
             }
-        } else {
-            if (!(ttyPath = strdup(argv->ttyPaths[0]))) {
-                virReportOOMError();
+        } else if (VIR_STRDUP(ttyPath, argv->ttyPaths[0]) < 0) {
                 goto cleanup;
-            }
         }
-    } else {
-        if (!(ttyPath = strdup("/dev/null"))) {
-            virReportOOMError();
+    } else if (VIR_STRDUP(ttyPath, "/dev/null") < 0) {
             goto cleanup;
-        }
     }
 
     VIR_DEBUG("Container TTY path: %s", ttyPath);
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index f1800eb..8c358c3 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -150,14 +150,16 @@ static virLXCControllerPtr virLXCControllerNew(const char *name)
     virDomainXMLOptionPtr xmlopt = NULL;
     char *configFile = NULL;
 
-    if (VIR_ALLOC(ctrl) < 0)
-        goto no_memory;
+    if (VIR_ALLOC(ctrl) < 0) {
+        virReportOOMError();
+        goto error;
+    }
 
     ctrl->timerShutdown = -1;
     ctrl->firstClient = true;
 
-    if (!(ctrl->name = strdup(name)))
-        goto no_memory;
+    if (VIR_STRDUP(ctrl->name, name) < 0)
+        goto error;
 
     if ((caps = lxcCapsInit(NULL)) == NULL)
         goto error;
@@ -186,8 +188,6 @@ cleanup:
     virObjectUnref(xmlopt);
     return ctrl;
 
-no_memory:
-    virReportOOMError();
 error:
     virLXCControllerFree(ctrl);
     ctrl = NULL;
@@ -1566,10 +1566,8 @@ int main(int argc, char *argv[])
             break;
 
         case 'n':
-            if ((name = strdup(optarg)) == NULL) {
-                virReportOOMError();
+            if (VIR_STRDUP(name, optarg) < 0)
                 goto cleanup;
-            }
             break;
 
         case 'v':
@@ -1577,10 +1575,8 @@ int main(int argc, char *argv[])
                 virReportOOMError();
                 goto cleanup;
             }
-            if ((veths[nveths++] = strdup(optarg)) == NULL) {
-                virReportOOMError();
+            if (VIR_STRDUP(veths[nveths++], optarg) < 0)
                 goto cleanup;
-            }
             break;
 
         case 'c':
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 84a97de..42e4989 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -626,10 +626,7 @@ static char *lxcDomainGetOSType(virDomainPtr dom)
         goto cleanup;
     }
 
-    ret = strdup(vm->def->os.type);
-
-    if (ret == NULL)
-        virReportOOMError();
+    ignore_value(VIR_STRDUP(ret, vm->def->os.type));
 
 cleanup:
     if (vm)
@@ -1629,9 +1626,7 @@ static char *lxcDomainGetSchedulerType(virDomainPtr dom,
             *nparams = 3;
     }
 
-    ret = strdup("posix");
-    if (!ret)
-        virReportOOMError();
+    ignore_value(VIR_STRDUP(ret, "posix"));
 
 cleanup:
     if (vm)
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index b10e81c..b06d748 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -996,9 +996,9 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm)
 
     root->type = VIR_DOMAIN_FS_TYPE_MOUNT;
 
-    if (!(root->src = strdup("/")) ||
-        !(root->dst = strdup("/")))
-        goto no_memory;
+    if (VIR_STRDUP(root->src, "/") < 0 ||
+        VIR_STRDUP(root->dst, "/") < 0)
+        goto error;
 
     if (VIR_INSERT_ELEMENT(vm->def->fss,
                            0,
@@ -1010,6 +1010,7 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm)
 
 no_memory:
     virReportOOMError();
+error:
     virDomainFSDefFree(root);
     return -1;
 }
-- 
1.8.1.5




More information about the libvir-list mailing list