提交 a96d7f3c 编写于 作者: M Michal Privoznik

Adapt to VIR_STRDUP and VIR_STRNDUP in src/lxc/*

上级 f75ed996
......@@ -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;
}
......
......@@ -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;
}
......@@ -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;
......@@ -1952,17 +1948,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);
......
......@@ -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':
......
......@@ -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)
......@@ -1636,9 +1633,7 @@ static char *lxcDomainGetSchedulerType(virDomainPtr dom,
*nparams = 3;
}
ret = strdup("posix");
if (!ret)
virReportOOMError();
ignore_value(VIR_STRDUP(ret, "posix"));
cleanup:
if (vm)
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册