1
0

Adapt to VIR_STRDUP and VIR_STRNDUP in src/lxc/*

This commit is contained in:
Michal Privoznik 2013-05-03 14:43:39 +02:00
parent f75ed996e7
commit a96d7f3c8f
6 changed files with 36 additions and 57 deletions

View File

@ -538,8 +538,7 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, bool startup)
goto cleanup; goto cleanup;
} }
if (!(res->partition = strdup("/machine"))) { if (VIR_STRDUP(res->partition, "/machine") < 0) {
virReportOOMError();
VIR_FREE(res); VIR_FREE(res);
goto cleanup; goto cleanup;
} }

View File

@ -37,7 +37,7 @@
#include "configmake.h" #include "configmake.h"
#include "lxc_container.h" #include "lxc_container.h"
#include "virnodesuspend.h" #include "virnodesuspend.h"
#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_LXC #define VIR_FROM_THIS VIR_FROM_LXC
@ -119,10 +119,10 @@ virCapsPtr lxcCapsInit(virLXCDriverPtr driver)
if (VIR_ALLOC(caps->host.secModels) < 0) if (VIR_ALLOC(caps->host.secModels) < 0)
goto no_memory; goto no_memory;
caps->host.nsecModels = 1; 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; goto error;
if (!(caps->host.secModels[0].doi = strdup(doi))) if (VIR_STRDUP(caps->host.secModels[0].doi, doi) < 0)
goto no_memory; goto error;
} }
VIR_DEBUG("Initialized caps for security driver \"%s\" with " VIR_DEBUG("Initialized caps for security driver \"%s\" with "
@ -161,18 +161,18 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver)
driver->securityRequireConfined = false; driver->securityRequireConfined = false;
/* Set the container configuration directory */ /* 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; goto error;
if ((driver->stateDir = strdup(LXC_STATE_DIR)) == NULL) if (VIR_STRDUP(driver->stateDir, LXC_STATE_DIR) < 0)
goto no_memory; goto error;
if ((driver->logDir = strdup(LXC_LOG_DIR)) == NULL) if (VIR_STRDUP(driver->logDir, LXC_LOG_DIR) < 0)
goto no_memory; goto error;
if ((driver->autostartDir = strdup(LXC_AUTOSTART_DIR)) == NULL) if (VIR_STRDUP(driver->autostartDir, LXC_AUTOSTART_DIR) < 0)
goto no_memory; goto error;
if ((filename = strdup(SYSCONFDIR "/libvirt/lxc.conf")) == NULL) if (VIR_STRDUP(filename, SYSCONFDIR "/libvirt/lxc.conf") < 0)
goto no_memory; goto error;
/* Avoid error from non-existant or unreadable file. */ /* Avoid error from non-existant or unreadable file. */
if (access(filename, R_OK) == -1) if (access(filename, R_OK) == -1)
@ -196,8 +196,7 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver)
p = virConfGetValue(conf, "security_driver"); p = virConfGetValue(conf, "security_driver");
CHECK_TYPE("security_driver", VIR_CONF_STRING); CHECK_TYPE("security_driver", VIR_CONF_STRING);
if (p && p->str) { if (p && p->str) {
if (!(driver->securityDriverName = strdup(p->str))) { if (VIR_STRDUP(driver->securityDriverName, p->str) < 0) {
virReportOOMError();
virConfFree(conf); virConfFree(conf);
return -1; return -1;
} }
@ -220,7 +219,6 @@ done:
VIR_FREE(filename); VIR_FREE(filename);
return 0; return 0;
no_memory: error:
virReportOOMError();
return -1; return -1;
} }

View File

@ -439,10 +439,8 @@ static int lxcContainerGetSubtree(const char *prefix,
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
if (!(mounts[nmounts] = strdup(mntent.mnt_dir))) { if (VIR_STRDUP(mounts[nmounts], mntent.mnt_dir) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
nmounts++; nmounts++;
VIR_DEBUG("Grabbed %s", mntent.mnt_dir); VIR_DEBUG("Grabbed %s", mntent.mnt_dir);
} }
@ -1041,10 +1039,8 @@ lxcContainerMountDetectFilesystem(const char *src, char **type)
goto cleanup; goto cleanup;
} }
if (!(*type = strdup(data))) { if (VIR_STRDUP(*type, data) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
done: done:
ret = 0; ret = 0;
@ -1952,17 +1948,11 @@ static int lxcContainerChild(void *data)
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
} else { } else if (VIR_STRDUP(ttyPath, argv->ttyPaths[0]) < 0) {
if (!(ttyPath = strdup(argv->ttyPaths[0]))) {
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
} else { } else if (VIR_STRDUP(ttyPath, "/dev/null") < 0) {
if (!(ttyPath = strdup("/dev/null"))) {
virReportOOMError();
goto cleanup; goto cleanup;
}
} }
VIR_DEBUG("Container TTY path: %s", ttyPath); VIR_DEBUG("Container TTY path: %s", ttyPath);

View File

@ -150,14 +150,16 @@ static virLXCControllerPtr virLXCControllerNew(const char *name)
virDomainXMLOptionPtr xmlopt = NULL; virDomainXMLOptionPtr xmlopt = NULL;
char *configFile = NULL; char *configFile = NULL;
if (VIR_ALLOC(ctrl) < 0) if (VIR_ALLOC(ctrl) < 0) {
goto no_memory; virReportOOMError();
goto error;
}
ctrl->timerShutdown = -1; ctrl->timerShutdown = -1;
ctrl->firstClient = true; ctrl->firstClient = true;
if (!(ctrl->name = strdup(name))) if (VIR_STRDUP(ctrl->name, name) < 0)
goto no_memory; goto error;
if ((caps = lxcCapsInit(NULL)) == NULL) if ((caps = lxcCapsInit(NULL)) == NULL)
goto error; goto error;
@ -186,8 +188,6 @@ cleanup:
virObjectUnref(xmlopt); virObjectUnref(xmlopt);
return ctrl; return ctrl;
no_memory:
virReportOOMError();
error: error:
virLXCControllerFree(ctrl); virLXCControllerFree(ctrl);
ctrl = NULL; ctrl = NULL;
@ -1566,10 +1566,8 @@ int main(int argc, char *argv[])
break; break;
case 'n': case 'n':
if ((name = strdup(optarg)) == NULL) { if (VIR_STRDUP(name, optarg) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
break; break;
case 'v': case 'v':
@ -1577,10 +1575,8 @@ int main(int argc, char *argv[])
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
if ((veths[nveths++] = strdup(optarg)) == NULL) { if (VIR_STRDUP(veths[nveths++], optarg) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
break; break;
case 'c': case 'c':

View File

@ -626,10 +626,7 @@ static char *lxcDomainGetOSType(virDomainPtr dom)
goto cleanup; goto cleanup;
} }
ret = strdup(vm->def->os.type); ignore_value(VIR_STRDUP(ret, vm->def->os.type));
if (ret == NULL)
virReportOOMError();
cleanup: cleanup:
if (vm) if (vm)
@ -1636,9 +1633,7 @@ static char *lxcDomainGetSchedulerType(virDomainPtr dom,
*nparams = 3; *nparams = 3;
} }
ret = strdup("posix"); ignore_value(VIR_STRDUP(ret, "posix"));
if (!ret)
virReportOOMError();
cleanup: cleanup:
if (vm) if (vm)

View File

@ -996,9 +996,9 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm)
root->type = VIR_DOMAIN_FS_TYPE_MOUNT; root->type = VIR_DOMAIN_FS_TYPE_MOUNT;
if (!(root->src = strdup("/")) || if (VIR_STRDUP(root->src, "/") < 0 ||
!(root->dst = strdup("/"))) VIR_STRDUP(root->dst, "/") < 0)
goto no_memory; goto error;
if (VIR_INSERT_ELEMENT(vm->def->fss, if (VIR_INSERT_ELEMENT(vm->def->fss,
0, 0,
@ -1010,6 +1010,7 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm)
no_memory: no_memory:
virReportOOMError(); virReportOOMError();
error:
virDomainFSDefFree(root); virDomainFSDefFree(root);
return -1; return -1;
} }