mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 13:05:27 +00:00
Adapt to VIR_ALLOC and virAsprintf in src/util/*
This commit is contained in:
parent
ae6ce5bf00
commit
a2f8babc7d
@ -95,10 +95,8 @@ runIO(const char *path, int fd, int oflags, unsigned long long length)
|
||||
}
|
||||
buf = base;
|
||||
#else
|
||||
if (VIR_ALLOC_N(buf, buflen + alignMask) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(buf, buflen + alignMask) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
base = buf;
|
||||
buf = (char *) (((intptr_t) base + alignMask) & ~alignMask);
|
||||
#endif
|
||||
|
@ -73,7 +73,7 @@ int virAuthGetConfigFilePath(virConnectPtr conn,
|
||||
goto cleanup;
|
||||
|
||||
if (virAsprintf(path, "%s/auth.conf", userdir) < 0)
|
||||
goto no_memory;
|
||||
goto cleanup;
|
||||
|
||||
VIR_DEBUG("Checking for readability of '%s'", *path);
|
||||
if (access(*path, R_OK) == 0)
|
||||
@ -98,10 +98,6 @@ cleanup:
|
||||
VIR_FREE(userdir);
|
||||
|
||||
return ret;
|
||||
|
||||
no_memory:
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,10 +42,8 @@ virAuthConfigPtr virAuthConfigNew(const char *path)
|
||||
{
|
||||
virAuthConfigPtr auth;
|
||||
|
||||
if (VIR_ALLOC(auth) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(auth) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (VIR_STRDUP(auth->path, path) < 0)
|
||||
goto error;
|
||||
@ -70,10 +68,8 @@ virAuthConfigPtr virAuthConfigNewData(const char *path,
|
||||
{
|
||||
virAuthConfigPtr auth;
|
||||
|
||||
if (VIR_ALLOC(auth) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(auth) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (VIR_STRDUP(auth->path, path) < 0)
|
||||
goto error;
|
||||
@ -121,10 +117,8 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
|
||||
if (!hostname)
|
||||
hostname = "localhost";
|
||||
|
||||
if (virAsprintf(&authgroup, "auth-%s-%s", service, hostname) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&authgroup, "auth-%s-%s", service, hostname) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!virKeyFileHasGroup(auth->keyfile, authgroup)) {
|
||||
ret = 0;
|
||||
@ -138,10 +132,8 @@ int virAuthConfigLookup(virAuthConfigPtr auth,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virAsprintf(&credgroup, "credentials-%s", authcred) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&credgroup, "credentials-%s", authcred) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!virKeyFileHasGroup(auth->keyfile, credgroup)) {
|
||||
virReportError(VIR_ERR_CONF_SYNTAX,
|
||||
|
@ -1171,7 +1171,7 @@ static int virCgroupPartitionEscape(char **path)
|
||||
if ((rc = virCgroupPartitionNeedsEscaping(*path)) <= 0)
|
||||
return rc;
|
||||
|
||||
if (VIR_INSERT_ELEMENT_QUIET(*path, 0, len, escape) < 0)
|
||||
if (VIR_INSERT_ELEMENT(*path, 0, len, escape) < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
@ -1204,7 +1204,6 @@ static int virCgroupSetPartitionSuffix(const char *path, char **res)
|
||||
if (VIR_REALLOC_N(tokens[i],
|
||||
strlen(tokens[i]) + strlen(".partition") + 1) < 0) {
|
||||
ret = -ENOMEM;
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
strcat(tokens[i], ".partition");
|
||||
@ -1212,8 +1211,6 @@ static int virCgroupSetPartitionSuffix(const char *path, char **res)
|
||||
|
||||
ret = virCgroupPartitionEscape(&(tokens[i]));
|
||||
if (ret < 0) {
|
||||
if (ret == -ENOMEM)
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
@ -2592,10 +2589,8 @@ int virCgroupIsolateMount(virCgroupPtr group, const char *oldroot,
|
||||
}
|
||||
|
||||
if (virAsprintf(&opts,
|
||||
"mode=755,size=65536%s", mountopts) < 0) {
|
||||
virReportOOMError();
|
||||
"mode=755,size=65536%s", mountopts) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) {
|
||||
virReportSystemError(errno,
|
||||
@ -2613,10 +2608,8 @@ int virCgroupIsolateMount(virCgroupPtr group, const char *oldroot,
|
||||
if (virAsprintf(&src, "%s%s%s",
|
||||
oldroot,
|
||||
group->controllers[i].mountPoint,
|
||||
group->controllers[i].placement) < 0) {
|
||||
virReportOOMError();
|
||||
group->controllers[i].placement) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
VIR_DEBUG("Create mount point '%s'", group->controllers[i].mountPoint);
|
||||
if (virFileMakePath(group->controllers[i].mountPoint) < 0) {
|
||||
|
@ -1840,17 +1840,13 @@ virCommandProcessIO(virCommandPtr cmd)
|
||||
* results accumulated over a prior run of the same command. */
|
||||
if (cmd->outbuf) {
|
||||
outfd = cmd->outfd;
|
||||
if (VIR_REALLOC_N(*cmd->outbuf, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_REALLOC_N(*cmd->outbuf, 1) < 0)
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
if (cmd->errbuf) {
|
||||
errfd = cmd->errfd;
|
||||
if (VIR_REALLOC_N(*cmd->errbuf, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_REALLOC_N(*cmd->errbuf, 1) < 0)
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
if (ret == -1)
|
||||
goto cleanup;
|
||||
@ -1924,10 +1920,8 @@ virCommandProcessIO(virCommandPtr cmd)
|
||||
else
|
||||
errfd = -1;
|
||||
} else {
|
||||
if (VIR_REALLOC_N(*buf, *len + done + 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_REALLOC_N(*buf, *len + done + 1) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
memcpy(*buf + *len, data, done);
|
||||
*len += done;
|
||||
}
|
||||
@ -2471,7 +2465,6 @@ int virCommandHandshakeWait(virCommandPtr cmd)
|
||||
char *msg;
|
||||
ssize_t len;
|
||||
if (VIR_ALLOC_N(msg, 1024) < 0) {
|
||||
virReportOOMError();
|
||||
VIR_FORCE_CLOSE(cmd->handshakeWait[0]);
|
||||
return -1;
|
||||
}
|
||||
|
@ -173,10 +173,8 @@ virConfNew(void)
|
||||
{
|
||||
virConfPtr ret;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
}
|
||||
ret->filename = NULL;
|
||||
ret->flags = 0;
|
||||
|
||||
@ -225,10 +223,8 @@ virConfAddEntry(virConfPtr conf, char *name, virConfValuePtr value, char *comm)
|
||||
if ((comm == NULL) && (name == NULL))
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret->name = name;
|
||||
ret->value = value;
|
||||
@ -529,7 +525,6 @@ virConfParseValue(virConfParserCtxtPtr ctxt)
|
||||
return NULL;
|
||||
}
|
||||
if (VIR_ALLOC(ret) < 0) {
|
||||
virReportOOMError();
|
||||
virConfFreeList(lst);
|
||||
VIR_FREE(str);
|
||||
return NULL;
|
||||
@ -883,7 +878,6 @@ virConfSetValue(virConfPtr conf,
|
||||
|
||||
if (!cur) {
|
||||
if (VIR_ALLOC(cur) < 0) {
|
||||
virReportOOMError();
|
||||
virConfFreeValue(value);
|
||||
return -1;
|
||||
}
|
||||
|
@ -112,11 +112,11 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile,
|
||||
|
||||
if (idx < 0) {
|
||||
if (VIR_REALLOC_N(addnhostsfile->hosts, addnhostsfile->nhosts + 1) < 0)
|
||||
goto alloc_error;
|
||||
goto error;
|
||||
|
||||
idx = addnhostsfile->nhosts;
|
||||
if (VIR_ALLOC(addnhostsfile->hosts[idx].hostnames) < 0)
|
||||
goto alloc_error;
|
||||
goto error;
|
||||
|
||||
if (VIR_STRDUP(addnhostsfile->hosts[idx].ip, ipstr) < 0)
|
||||
goto error;
|
||||
@ -126,7 +126,7 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile,
|
||||
}
|
||||
|
||||
if (VIR_REALLOC_N(addnhostsfile->hosts[idx].hostnames, addnhostsfile->hosts[idx].nhostnames + 1) < 0)
|
||||
goto alloc_error;
|
||||
goto error;
|
||||
|
||||
if (VIR_STRDUP(addnhostsfile->hosts[idx].hostnames[addnhostsfile->hosts[idx].nhostnames],
|
||||
name) < 0)
|
||||
@ -138,8 +138,6 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile,
|
||||
|
||||
return 0;
|
||||
|
||||
alloc_error:
|
||||
virReportOOMError();
|
||||
error:
|
||||
VIR_FREE(ipstr);
|
||||
return -1;
|
||||
@ -151,19 +149,15 @@ addnhostsNew(const char *name,
|
||||
{
|
||||
dnsmasqAddnHostsfile *addnhostsfile;
|
||||
|
||||
if (VIR_ALLOC(addnhostsfile) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(addnhostsfile) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
addnhostsfile->hosts = NULL;
|
||||
addnhostsfile->nhosts = 0;
|
||||
|
||||
if (virAsprintf(&addnhostsfile->path, "%s/%s.%s", config_dir, name,
|
||||
DNSMASQ_ADDNHOSTSFILE_SUFFIX) < 0) {
|
||||
virReportOOMError();
|
||||
DNSMASQ_ADDNHOSTSFILE_SUFFIX) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
return addnhostsfile;
|
||||
|
||||
@ -311,7 +305,7 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile,
|
||||
{
|
||||
char *ipstr = NULL;
|
||||
if (VIR_REALLOC_N(hostsfile->hosts, hostsfile->nhosts + 1) < 0)
|
||||
goto alloc_error;
|
||||
goto error;
|
||||
|
||||
if (!(ipstr = virSocketAddrFormat(ip)))
|
||||
return -1;
|
||||
@ -321,28 +315,28 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile,
|
||||
if (name && id) {
|
||||
if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
|
||||
"id:%s,%s,[%s]", id, name, ipstr) < 0)
|
||||
goto alloc_error;
|
||||
goto error;
|
||||
} else if (name && !id) {
|
||||
if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
|
||||
"%s,[%s]", name, ipstr) < 0)
|
||||
goto alloc_error;
|
||||
goto error;
|
||||
} else if (!name && id) {
|
||||
if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host,
|
||||
"id:%s,[%s]", id, ipstr) < 0)
|
||||
goto alloc_error;
|
||||
goto error;
|
||||
}
|
||||
} else if (name && mac) {
|
||||
if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s,%s",
|
||||
mac, ipstr, name) < 0)
|
||||
goto alloc_error;
|
||||
goto error;
|
||||
} else if (name && !mac){
|
||||
if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s",
|
||||
name, ipstr) < 0)
|
||||
goto alloc_error;
|
||||
goto error;
|
||||
} else {
|
||||
if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s",
|
||||
mac, ipstr) < 0)
|
||||
goto alloc_error;
|
||||
goto error;
|
||||
}
|
||||
VIR_FREE(ipstr);
|
||||
|
||||
@ -350,8 +344,7 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile,
|
||||
|
||||
return 0;
|
||||
|
||||
alloc_error:
|
||||
virReportOOMError();
|
||||
error:
|
||||
VIR_FREE(ipstr);
|
||||
return -1;
|
||||
}
|
||||
@ -362,19 +355,15 @@ hostsfileNew(const char *name,
|
||||
{
|
||||
dnsmasqHostsfile *hostsfile;
|
||||
|
||||
if (VIR_ALLOC(hostsfile) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(hostsfile) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hostsfile->hosts = NULL;
|
||||
hostsfile->nhosts = 0;
|
||||
|
||||
if (virAsprintf(&hostsfile->path, "%s/%s.%s", config_dir, name,
|
||||
DNSMASQ_HOSTSFILE_SUFFIX) < 0) {
|
||||
virReportOOMError();
|
||||
DNSMASQ_HOSTSFILE_SUFFIX) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
return hostsfile;
|
||||
|
||||
@ -466,10 +455,8 @@ dnsmasqContextNew(const char *network_name,
|
||||
{
|
||||
dnsmasqContext *ctx;
|
||||
|
||||
if (VIR_ALLOC(ctx) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(ctx) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (VIR_STRDUP(ctx->config_dir, config_dir) < 0)
|
||||
goto error;
|
||||
@ -772,10 +759,8 @@ dnsmasqCapsRefreshInternal(dnsmasqCapsPtr caps, bool force)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virAsprintf(&complete, "%s\n%s", version, help) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&complete, "%s\n%s", version, help) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = dnsmasqCapsSetFromBuffer(caps, complete);
|
||||
|
||||
@ -796,10 +781,8 @@ dnsmasqCapsNewEmpty(const char *binaryPath)
|
||||
return NULL;
|
||||
if (!(caps = virObjectNew(dnsmasqCapsClass)))
|
||||
return NULL;
|
||||
if (!(caps->flags = virBitmapNew(DNSMASQ_CAPS_LAST))) {
|
||||
virReportOOMError();
|
||||
if (!(caps->flags = virBitmapNew(DNSMASQ_CAPS_LAST)))
|
||||
goto error;
|
||||
}
|
||||
if (VIR_STRDUP(caps->binaryPath, binaryPath ? binaryPath : DNSMASQ) < 0)
|
||||
goto error;
|
||||
return caps;
|
||||
|
@ -379,10 +379,8 @@ static struct pollfd *virEventPollMakePollFDs(int *nfds) {
|
||||
}
|
||||
|
||||
/* Setup the poll file handle data structs */
|
||||
if (VIR_ALLOC_N(fds, *nfds) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(fds, *nfds) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*nfds = 0;
|
||||
for (i = 0; i < eventLoop.handlesCount; i++) {
|
||||
|
@ -211,10 +211,8 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned int flags)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(ret) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mode = fcntl(*fd, F_GETFL);
|
||||
|
||||
@ -426,10 +424,8 @@ virFileRewrite(const char *path,
|
||||
int fd = -1;
|
||||
int ret = -1;
|
||||
|
||||
if (virAsprintf(&newfile, "%s.new", path) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&newfile, "%s.new", path) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((fd = open(newfile, O_WRONLY | O_CREAT | O_TRUNC, mode)) < 0) {
|
||||
virReportSystemError(errno, _("cannot create file '%s'"),
|
||||
@ -553,10 +549,8 @@ static int virFileLoopDeviceOpen(char **dev_name)
|
||||
if (!STRPREFIX(de->d_name, "loop"))
|
||||
continue;
|
||||
|
||||
if (virAsprintf(&looppath, "/dev/%s", de->d_name) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&looppath, "/dev/%s", de->d_name) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
VIR_DEBUG("Checking up on device %s", looppath);
|
||||
if ((fd = open(looppath, O_RDWR)) < 0) {
|
||||
@ -666,10 +660,8 @@ virFileNBDDeviceIsBusy(const char *devname)
|
||||
int ret = -1;
|
||||
|
||||
if (virAsprintf(&path, SYSFS_BLOCK_DIR "/%s/pid",
|
||||
devname) < 0) {
|
||||
virReportOOMError();
|
||||
devname) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (access(path, F_OK) < 0) {
|
||||
if (errno == ENOENT)
|
||||
@ -709,10 +701,8 @@ virFileNBDDeviceFindUnused(void)
|
||||
if (rv < 0)
|
||||
goto cleanup;
|
||||
if (rv == 0) {
|
||||
if (virAsprintf(&ret, "/dev/%s", de->d_name) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&ret, "/dev/%s", de->d_name) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
@ -847,10 +837,8 @@ int virFileDeleteTree(const char *dir)
|
||||
continue;
|
||||
|
||||
if (virAsprintf(&filepath, "%s/%s",
|
||||
dir, de->d_name) < 0) {
|
||||
virReportOOMError();
|
||||
dir, de->d_name) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (lstat(filepath, &sb) < 0) {
|
||||
virReportSystemError(errno, _("Cannot access '%s'"),
|
||||
@ -2064,15 +2052,9 @@ virFileBuildPath(const char *dir, const char *name, const char *ext)
|
||||
char *path;
|
||||
|
||||
if (ext == NULL) {
|
||||
if (virAsprintf(&path, "%s/%s", dir, name) < 0) {
|
||||
virReportOOMError();
|
||||
return NULL;
|
||||
}
|
||||
ignore_value(virAsprintf(&path, "%s/%s", dir, name));
|
||||
} else {
|
||||
if (virAsprintf(&path, "%s/%s%s", dir, name, ext) < 0) {
|
||||
virReportOOMError();
|
||||
return NULL;
|
||||
}
|
||||
ignore_value(virAsprintf(&path, "%s/%s%s", dir, name, ext));
|
||||
}
|
||||
|
||||
return path;
|
||||
|
@ -129,10 +129,8 @@ virHashTablePtr virHashCreateFull(ssize_t size,
|
||||
if (size <= 0)
|
||||
size = 256;
|
||||
|
||||
if (VIR_ALLOC(table) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(table) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
table->seed = virRandomBits(32);
|
||||
table->size = size;
|
||||
@ -144,7 +142,6 @@ virHashTablePtr virHashCreateFull(ssize_t size,
|
||||
table->keyFree = keyFree;
|
||||
|
||||
if (VIR_ALLOC_N(table->table, size) < 0) {
|
||||
virReportOOMError();
|
||||
VIR_FREE(table);
|
||||
return NULL;
|
||||
}
|
||||
@ -204,7 +201,6 @@ virHashGrow(virHashTablePtr table, size_t size)
|
||||
return -1;
|
||||
|
||||
if (VIR_ALLOC_N(table->table, size) < 0) {
|
||||
virReportOOMError();
|
||||
table->table = oldtable;
|
||||
return -1;
|
||||
}
|
||||
@ -302,7 +298,6 @@ virHashAddOrUpdateEntry(virHashTablePtr table, const void *name,
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(entry) < 0 || !(new_name = table->keyCopy(name))) {
|
||||
virReportOOMError();
|
||||
VIR_FREE(entry);
|
||||
return -1;
|
||||
}
|
||||
@ -673,10 +668,8 @@ virHashKeyValuePairPtr virHashGetItems(virHashTablePtr table,
|
||||
if (numElems < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(iter.sortArray, numElems + 1)) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(iter.sortArray, numElems + 1))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virHashForEach(table, virHashGetKeysIterator, &iter);
|
||||
|
||||
|
@ -142,10 +142,8 @@ virIdentityPtr virIdentityGetSystem(void)
|
||||
char *processid = NULL;
|
||||
|
||||
if (virAsprintf(&processid, "%llu",
|
||||
(unsigned long long)getpid()) < 0) {
|
||||
virReportOOMError();
|
||||
(unsigned long long)getpid()) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(username = virGetUserName(getuid())))
|
||||
goto cleanup;
|
||||
|
@ -132,10 +132,8 @@ int virInitctlSetRunLevel(virInitctlRunLevel level,
|
||||
req.runlevel = '0' + level;
|
||||
|
||||
if (vroot) {
|
||||
if (virAsprintf(&path, "%s/%s", vroot, VIR_INITCTL_FIFO) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&path, "%s/%s", vroot, VIR_INITCTL_FIFO) < 0)
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (VIR_STRDUP(path, VIR_INITCTL_FIFO) < 0)
|
||||
return -1;
|
||||
|
@ -266,8 +266,7 @@ static char *iptablesFormatNetwork(virSocketAddr *netaddr,
|
||||
if (!netstr)
|
||||
return NULL;
|
||||
|
||||
if (virAsprintf(&ret, "%s/%d", netstr, prefix) < 0)
|
||||
virReportOOMError();
|
||||
ignore_value(virAsprintf(&ret, "%s/%d", netstr, prefix));
|
||||
|
||||
VIR_FREE(netstr);
|
||||
return ret;
|
||||
@ -738,10 +737,8 @@ iptablesForwardMasquerade(virSocketAddr *netaddr,
|
||||
|
||||
if (port->start < port->end && port->end < 65536) {
|
||||
if (virAsprintf(&portRangeStr, ":%u-%u",
|
||||
port->start, port->end) < 0) {
|
||||
virReportOOMError();
|
||||
port->start, port->end) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Invalid port range '%u-%u'."),
|
||||
@ -761,10 +758,8 @@ iptablesForwardMasquerade(virSocketAddr *netaddr,
|
||||
portRangeStr ? portRangeStr : "");
|
||||
}
|
||||
|
||||
if (r < 0) {
|
||||
virReportOOMError();
|
||||
if (r < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
virCommandAddArgList(cmd, "--jump", "SNAT",
|
||||
"--to-source", natRangeStr, NULL);
|
||||
|
@ -282,10 +282,8 @@ virKeyFilePtr virKeyFileNew(void)
|
||||
{
|
||||
virKeyFilePtr conf;
|
||||
|
||||
if (VIR_ALLOC(conf) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(conf) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(conf->groups = virHashCreate(10,
|
||||
virKeyFileEntryFree)))
|
||||
|
@ -64,16 +64,10 @@ static char *virLockSpaceGetResourcePath(virLockSpacePtr lockspace,
|
||||
const char *resname)
|
||||
{
|
||||
char *ret;
|
||||
if (lockspace->dir) {
|
||||
if (virAsprintf(&ret, "%s/%s", lockspace->dir, resname) < 0) {
|
||||
virReportOOMError();
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
if (VIR_STRDUP(ret, resname) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (lockspace->dir)
|
||||
ignore_value(virAsprintf(&ret, "%s/%s", lockspace->dir, resname));
|
||||
else
|
||||
ignore_value(VIR_STRDUP(ret, resname));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -134,7 +128,7 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace,
|
||||
goto error;
|
||||
|
||||
if (!(res->path = virLockSpaceGetResourcePath(lockspace, resname)))
|
||||
goto no_memory;
|
||||
goto error;
|
||||
|
||||
if (flags & VIR_LOCK_SPACE_ACQUIRE_AUTOCREATE) {
|
||||
while (1) {
|
||||
@ -223,14 +217,12 @@ virLockSpaceResourceNew(virLockSpacePtr lockspace,
|
||||
res->lockHeld = true;
|
||||
|
||||
if (VIR_EXPAND_N(res->owners, res->nOwners, 1) < 0)
|
||||
goto no_memory;
|
||||
goto error;
|
||||
|
||||
res->owners[res->nOwners-1] = owner;
|
||||
|
||||
return res;
|
||||
|
||||
no_memory:
|
||||
virReportOOMError();
|
||||
error:
|
||||
virLockSpaceResourceFree(res);
|
||||
return NULL;
|
||||
@ -343,10 +335,8 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
|
||||
size_t j;
|
||||
int m;
|
||||
|
||||
if (VIR_ALLOC(res) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(res) < 0)
|
||||
goto error;
|
||||
}
|
||||
res->fd = -1;
|
||||
|
||||
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
||||
@ -412,7 +402,6 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
|
||||
|
||||
res->nOwners = m;
|
||||
if (VIR_ALLOC_N(res->owners, res->nOwners) < 0) {
|
||||
virReportOOMError();
|
||||
virLockSpaceResourceFree(res);
|
||||
goto error;
|
||||
}
|
||||
@ -451,10 +440,8 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpacePtr lockspace)
|
||||
virJSONValuePtr resources;
|
||||
virHashKeyValuePairPtr pairs = NULL, tmp;
|
||||
|
||||
if (!object) {
|
||||
virReportOOMError();
|
||||
if (!object)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virMutexLock(&lockspace->lock);
|
||||
|
||||
@ -477,10 +464,8 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpacePtr lockspace)
|
||||
virJSONValuePtr owners = NULL;
|
||||
size_t i;
|
||||
|
||||
if (!child) {
|
||||
virReportOOMError();
|
||||
if (!child)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (virJSONValueArrayAppend(resources, child) < 0) {
|
||||
virJSONValueFree(child);
|
||||
@ -641,10 +626,8 @@ int virLockSpaceAcquireResource(virLockSpacePtr lockspace,
|
||||
if ((res->flags & VIR_LOCK_SPACE_ACQUIRE_SHARED) &&
|
||||
(flags & VIR_LOCK_SPACE_ACQUIRE_SHARED)) {
|
||||
|
||||
if (VIR_EXPAND_N(res->owners, res->nOwners, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_EXPAND_N(res->owners, res->nOwners, 1) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
res->owners[res->nOwners-1] = owner;
|
||||
|
||||
goto done;
|
||||
|
@ -315,10 +315,8 @@ virNetDevReplaceMacAddress(const char *linkdev,
|
||||
|
||||
if (virAsprintf(&path, "%s/%s",
|
||||
stateDir,
|
||||
linkdev) < 0) {
|
||||
virReportOOMError();
|
||||
linkdev) < 0)
|
||||
return -1;
|
||||
}
|
||||
virMacAddrFormat(&oldmac, macstr);
|
||||
if (virFileWriteStr(path, macstr, O_CREAT|O_TRUNC|O_WRONLY) < 0) {
|
||||
virReportSystemError(errno, _("Unable to preserve mac for %s"),
|
||||
@ -352,10 +350,8 @@ virNetDevRestoreMacAddress(const char *linkdev,
|
||||
|
||||
if (virAsprintf(&path, "%s/%s",
|
||||
stateDir,
|
||||
linkdev) < 0) {
|
||||
virReportOOMError();
|
||||
linkdev) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (virFileReadAll(path, VIR_MAC_STRING_BUFLEN, &macstr) < 0)
|
||||
return -1;
|
||||
@ -505,10 +501,8 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
|
||||
"ip", "link", "set", ifname, "netns", NULL, NULL
|
||||
};
|
||||
|
||||
if (virAsprintf(&pid, "%lld", (long long) pidInNs) == -1) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&pid, "%lld", (long long) pidInNs) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
argv[5] = pid;
|
||||
rc = virRun(argv, NULL);
|
||||
@ -1056,13 +1050,7 @@ virNetDevSysfsFile(char **pf_sysfs_device_link, const char *ifname,
|
||||
const char *file)
|
||||
{
|
||||
|
||||
if (virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/%s",
|
||||
ifname, file) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/%s", ifname, file);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -1070,13 +1058,8 @@ virNetDevSysfsDeviceFile(char **pf_sysfs_device_link, const char *ifname,
|
||||
const char *file)
|
||||
{
|
||||
|
||||
if (virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/device/%s",
|
||||
ifname, file) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/device/%s",
|
||||
ifname, file);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1110,10 +1093,8 @@ virNetDevGetVirtualFunctions(const char *pfname,
|
||||
n_vfname) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (VIR_ALLOC_N(*vfname, *n_vfname) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(*vfname, *n_vfname) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
for (i = 0; i < *n_vfname; i++)
|
||||
{
|
||||
@ -1661,16 +1642,12 @@ virNetDevReplaceVfConfig(const char *pflinkdev, int vf,
|
||||
goto cleanup;
|
||||
|
||||
if (virAsprintf(&path, "%s/%s_vf%d",
|
||||
stateDir, pflinkdev, vf) < 0) {
|
||||
virReportOOMError();
|
||||
stateDir, pflinkdev, vf) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virAsprintf(&fileData, "%s\n%d\n",
|
||||
virMacAddrFormat(&oldmac, macstr), oldvlanid) < 0) {
|
||||
virReportOOMError();
|
||||
virMacAddrFormat(&oldmac, macstr), oldvlanid) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
if (virFileWriteStr(path, fileData, O_CREAT|O_TRUNC|O_WRONLY) < 0) {
|
||||
virReportSystemError(errno, _("Unable to preserve mac/vlan tag "
|
||||
"for pf = %s, vf = %d"), pflinkdev, vf);
|
||||
@ -1699,10 +1676,8 @@ virNetDevRestoreVfConfig(const char *pflinkdev, int vf,
|
||||
int ifindex = -1;
|
||||
|
||||
if (virAsprintf(&path, "%s/%s_vf%d",
|
||||
stateDir, pflinkdev, vf) < 0) {
|
||||
virReportOOMError();
|
||||
stateDir, pflinkdev, vf) < 0)
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (virFileReadAll(path, 128, &fileData) < 0) {
|
||||
goto cleanup;
|
||||
|
@ -297,22 +297,17 @@ virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(*dest) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(*dest) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (src->in) {
|
||||
if (VIR_ALLOC((*dest)->in) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC((*dest)->in) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
memcpy((*dest)->in, src->in, sizeof(*src->in));
|
||||
}
|
||||
|
||||
if (src->out) {
|
||||
if (VIR_ALLOC((*dest)->out) < 0) {
|
||||
virReportOOMError();
|
||||
VIR_FREE((*dest)->in);
|
||||
goto cleanup;
|
||||
}
|
||||
@ -417,10 +412,8 @@ virNetDevBandwidthPlug(const char *brname,
|
||||
virAsprintf(&floor, "%llukbps", bandwidth->in->floor) < 0 ||
|
||||
virAsprintf(&ceil, "%llukbps", net_bandwidth->in->peak ?
|
||||
net_bandwidth->in->peak :
|
||||
net_bandwidth->in->average) < 0) {
|
||||
virReportOOMError();
|
||||
net_bandwidth->in->average) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cmd = virCommandNew(TC);
|
||||
virCommandAddArgList(cmd, "class", "add", "dev", brname, "parent", "1:1",
|
||||
@ -497,10 +490,8 @@ virNetDevBandwidthUnplug(const char *brname,
|
||||
|
||||
if (virAsprintf(&class_id, "1:%x", id) < 0 ||
|
||||
virAsprintf(&qdisc_id, "%x:", id) < 0 ||
|
||||
virAsprintf(&filter_id, "%u", id) < 0) {
|
||||
virReportOOMError();
|
||||
virAsprintf(&filter_id, "%u", id) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cmd = virCommandNew(TC);
|
||||
virCommandAddArgList(cmd, "qdisc", "del", "dev", brname,
|
||||
@ -564,10 +555,8 @@ virNetDevBandwidthUpdateRate(const char *ifname,
|
||||
if (virAsprintf(&rate, "%llukbps", new_rate) < 0 ||
|
||||
virAsprintf(&ceil, "%llukbps", bandwidth->in->peak ?
|
||||
bandwidth->in->peak :
|
||||
bandwidth->in->average) < 0) {
|
||||
virReportOOMError();
|
||||
bandwidth->in->average) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cmd = virCommandNew(TC);
|
||||
virCommandAddArgList(cmd, "class", "change", "dev", ifname,
|
||||
|
@ -108,10 +108,8 @@ static int virNetDevBridgeSet(const char *brname,
|
||||
char *path = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (virAsprintf(&path, "%s/%s/bridge/%s", SYSFS_NET_DIR, brname, paramname) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&path, "%s/%s/bridge/%s", SYSFS_NET_DIR, brname, paramname) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (virFileExists(path)) {
|
||||
char valuestr[INT_BUFSIZE_BOUND(value)];
|
||||
@ -157,10 +155,8 @@ static int virNetDevBridgeGet(const char *brname,
|
||||
char *path = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (virAsprintf(&path, "%s/%s/bridge/%s", SYSFS_NET_DIR, brname, paramname) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&path, "%s/%s/bridge/%s", SYSFS_NET_DIR, brname, paramname) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (virFileExists(path)) {
|
||||
char *valuestr;
|
||||
|
@ -764,11 +764,11 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
|
||||
|
||||
if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE)) {
|
||||
if (VIR_ALLOC(calld) < 0)
|
||||
goto memory_error;
|
||||
goto error;
|
||||
if (VIR_STRDUP(calld->cr_ifname, ifname) < 0)
|
||||
goto error;
|
||||
if (VIR_ALLOC(calld->virtPortProfile) < 0)
|
||||
goto memory_error;
|
||||
goto error;
|
||||
memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile));
|
||||
virMacAddrSet(&calld->macaddress, macaddress);
|
||||
if (VIR_STRDUP(calld->linkdev, linkdev) < 0)
|
||||
@ -785,8 +785,6 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
|
||||
|
||||
return 0;
|
||||
|
||||
memory_error:
|
||||
virReportOOMError();
|
||||
error:
|
||||
virNetlinkCallbackDataFree(calld);
|
||||
return -1;
|
||||
|
@ -68,17 +68,17 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
|
||||
|
||||
if (virAsprintf(&attachedmac_ex_id, "external-ids:attached-mac=\"%s\"",
|
||||
macaddrstr) < 0)
|
||||
goto out_of_memory;
|
||||
goto cleanup;
|
||||
if (virAsprintf(&ifaceid_ex_id, "external-ids:iface-id=\"%s\"",
|
||||
ifuuidstr) < 0)
|
||||
goto out_of_memory;
|
||||
goto cleanup;
|
||||
if (virAsprintf(&vmid_ex_id, "external-ids:vm-id=\"%s\"",
|
||||
vmuuidstr) < 0)
|
||||
goto out_of_memory;
|
||||
goto cleanup;
|
||||
if (ovsport->profileID[0] != '\0') {
|
||||
if (virAsprintf(&profile_ex_id, "external-ids:port-profile=\"%s\"",
|
||||
ovsport->profileID) < 0)
|
||||
goto out_of_memory;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cmd = virCommandNew(OVSVSCTL);
|
||||
@ -118,8 +118,10 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
|
||||
virBufferAsprintf(&buf, "%d", virtVlan->tag[i]);
|
||||
}
|
||||
|
||||
if (virBufferError(&buf))
|
||||
goto out_of_memory;
|
||||
if (virBufferError(&buf)) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
virCommandAddArg(cmd, virBufferCurrentContent(&buf));
|
||||
} else if (virtVlan->nTags) {
|
||||
virCommandAddArgFormat(cmd, "tag=%d", virtVlan->tag[0]);
|
||||
@ -161,10 +163,6 @@ cleanup:
|
||||
VIR_FREE(profile_ex_id);
|
||||
virCommandFree(cmd);
|
||||
return ret;
|
||||
|
||||
out_of_memory:
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -314,10 +314,8 @@ int virNetDevTapCreate(char **ifname,
|
||||
int i;
|
||||
for (i = 0; i <= IF_MAXUNIT; i++) {
|
||||
char *newname;
|
||||
if (virAsprintf(&newname, *ifname, i) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&newname, *ifname, i) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virNetDevExists(newname) == 0) {
|
||||
newifname = newname;
|
||||
@ -339,10 +337,8 @@ int virNetDevTapCreate(char **ifname,
|
||||
|
||||
if (tapfd) {
|
||||
char *dev_path = NULL;
|
||||
if (virAsprintf(&dev_path, "/dev/%s", ifr.ifr_name) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&dev_path, "/dev/%s", ifr.ifr_name) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((*tapfd = open(dev_path, O_RDWR)) < 0) {
|
||||
virReportSystemError(errno,
|
||||
|
@ -56,18 +56,14 @@ static int virNetDevVethGetFreeName(char **veth, int startDev)
|
||||
do {
|
||||
VIR_FREE(path);
|
||||
++devNum;
|
||||
if (virAsprintf(&path, "/sys/class/net/veth%d/", devNum) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&path, "/sys/class/net/veth%d/", devNum) < 0)
|
||||
return -1;
|
||||
}
|
||||
VIR_DEBUG("Probe %s", path);
|
||||
} while (virFileExists(path));
|
||||
VIR_FREE(path);
|
||||
|
||||
if (virAsprintf(veth, "veth%d", devNum) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(veth, "veth%d", devNum) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return devNum;
|
||||
}
|
||||
|
@ -86,10 +86,8 @@ virNetDevVlanCopy(virNetDevVlanPtr dst, const virNetDevVlanPtr src)
|
||||
if (!src || src->nTags == 0)
|
||||
return 0;
|
||||
|
||||
if (VIR_ALLOC_N(dst->tag, src->nTags) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(dst->tag, src->nTags) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
dst->trunk = src->trunk;
|
||||
dst->nTags = src->nTags;
|
||||
|
@ -410,10 +410,8 @@ int virNetDevVPortProfileMerge3(virNetDevVPortProfilePtr *result,
|
||||
}
|
||||
|
||||
/* at least one of the source profiles is non-empty */
|
||||
if (VIR_ALLOC(*result) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(*result) < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* start with the interface's profile. There are no pointers in a
|
||||
* virtualPortProfile, so a shallow copy is sufficient.
|
||||
|
@ -516,10 +516,8 @@ virNetlinkEventServiceStart(unsigned int protocol, unsigned int groups)
|
||||
|
||||
VIR_INFO("starting netlink event service with protocol %d", protocol);
|
||||
|
||||
if (VIR_ALLOC(srv) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(srv) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (virMutexInit(&srv->lock) < 0) {
|
||||
VIR_FREE(srv);
|
||||
@ -645,10 +643,8 @@ virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB,
|
||||
VIR_DEBUG("Used %zu handle slots, adding at least %d more",
|
||||
srv->handlesAlloc, NETLINK_EVENT_ALLOC_EXTENT);
|
||||
if (VIR_RESIZE_N(srv->handles, srv->handlesAlloc,
|
||||
srv->handlesCount, NETLINK_EVENT_ALLOC_EXTENT) < 0) {
|
||||
virReportOOMError();
|
||||
srv->handlesCount, NETLINK_EVENT_ALLOC_EXTENT) < 0)
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
r = srv->handlesCount++;
|
||||
|
||||
|
@ -132,10 +132,8 @@ virClassPtr virClassNew(virClassPtr parent,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(klass) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(klass) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
klass->parent = parent;
|
||||
if (VIR_STRDUP(klass->name, name) < 0)
|
||||
@ -191,10 +189,8 @@ void *virObjectNew(virClassPtr klass)
|
||||
|
||||
if (VIR_ALLOC_VAR(obj,
|
||||
char,
|
||||
klass->objectSize - sizeof(virObject)) < 0) {
|
||||
virReportOOMError();
|
||||
klass->objectSize - sizeof(virObject)) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
obj->magic = klass->magic;
|
||||
obj->klass = klass;
|
||||
|
@ -480,10 +480,8 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr dev, int cfgfd)
|
||||
* device is a VF, we just assume FLR works
|
||||
*/
|
||||
|
||||
if (virAsprintf(&path, PCI_SYSFS "devices/%s/physfn", dev->name) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&path, PCI_SYSFS "devices/%s/physfn", dev->name) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
found = virFileExists(path);
|
||||
VIR_FREE(path);
|
||||
@ -846,12 +844,7 @@ virPCIDriverDir(char **buffer, const char *driver)
|
||||
{
|
||||
VIR_FREE(*buffer);
|
||||
|
||||
if (virAsprintf(buffer, PCI_SYSFS "drivers/%s", driver) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return virAsprintf(buffer, PCI_SYSFS "drivers/%s", driver);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -859,12 +852,7 @@ virPCIDriverFile(char **buffer, const char *driver, const char *file)
|
||||
{
|
||||
VIR_FREE(*buffer);
|
||||
|
||||
if (virAsprintf(buffer, PCI_SYSFS "drivers/%s/%s", driver, file) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return virAsprintf(buffer, PCI_SYSFS "drivers/%s/%s", driver, file);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -872,12 +860,7 @@ virPCIFile(char **buffer, const char *device, const char *file)
|
||||
{
|
||||
VIR_FREE(*buffer);
|
||||
|
||||
if (virAsprintf(buffer, PCI_SYSFS "devices/%s/%s", device, file) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return virAsprintf(buffer, PCI_SYSFS "devices/%s/%s", device, file);
|
||||
}
|
||||
|
||||
|
||||
@ -1468,10 +1451,8 @@ virPCIDeviceNew(unsigned int domain,
|
||||
char *vendor = NULL;
|
||||
char *product = NULL;
|
||||
|
||||
if (VIR_ALLOC(dev) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(dev) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dev->domain = domain;
|
||||
dev->bus = bus;
|
||||
@ -1487,10 +1468,8 @@ virPCIDeviceNew(unsigned int domain,
|
||||
goto error;
|
||||
}
|
||||
if (virAsprintf(&dev->path, PCI_SYSFS "devices/%s/config",
|
||||
dev->name) < 0) {
|
||||
virReportOOMError();
|
||||
dev->name) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (access(dev->path, F_OK) != 0) {
|
||||
virReportSystemError(errno,
|
||||
@ -1537,10 +1516,8 @@ virPCIDeviceCopy(virPCIDevicePtr dev)
|
||||
{
|
||||
virPCIDevicePtr copy;
|
||||
|
||||
if (VIR_ALLOC(copy) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(copy) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* shallow copy to take care of most attributes */
|
||||
*copy = *dev;
|
||||
@ -1693,10 +1670,8 @@ virPCIDeviceListAdd(virPCIDeviceListPtr list,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (VIR_REALLOC_N(list->devs, list->count+1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_REALLOC_N(list->devs, list->count+1) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
list->devs[list->count++] = dev;
|
||||
|
||||
@ -1835,10 +1810,8 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev,
|
||||
struct dirent *ent;
|
||||
|
||||
if (virAsprintf(&pcidir, "/sys/bus/pci/devices/%04x:%02x:%02x.%x",
|
||||
dev->domain, dev->bus, dev->slot, dev->function) < 0) {
|
||||
virReportOOMError();
|
||||
dev->domain, dev->bus, dev->slot, dev->function) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(dir = opendir(pcidir))) {
|
||||
virReportSystemError(errno,
|
||||
@ -1855,10 +1828,8 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev,
|
||||
STRPREFIX(ent->d_name, "resource") ||
|
||||
STREQ(ent->d_name, "rom") ||
|
||||
STREQ(ent->d_name, "reset")) {
|
||||
if (virAsprintf(&file, "%s/%s", pcidir, ent->d_name) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&file, "%s/%s", pcidir, ent->d_name) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
if ((actor)(dev, file, opaque) < 0)
|
||||
goto cleanup;
|
||||
|
||||
@ -1894,10 +1865,8 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
|
||||
|
||||
if (virAsprintf(&groupPath,
|
||||
PCI_SYSFS "devices/%04x:%02x:%02x.%x/iommu_group/devices",
|
||||
orig->domain, orig->bus, orig->slot, orig->function) < 0) {
|
||||
virReportOOMError();
|
||||
orig->domain, orig->bus, orig->slot, orig->function) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(groupDir = opendir(groupPath))) {
|
||||
/* just process the original device, nothing more */
|
||||
@ -2008,11 +1977,9 @@ virPCIGetIOMMUGroupAddressesAddOne(virPCIDeviceAddressPtr newDevAddr, void *opaq
|
||||
|
||||
*copyAddr = *newDevAddr;
|
||||
|
||||
if (VIR_APPEND_ELEMENT_QUIET(*addrList->iommuGroupDevices,
|
||||
*addrList->nIommuGroupDevices, copyAddr) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_APPEND_ELEMENT(*addrList->iommuGroupDevices,
|
||||
*addrList->nIommuGroupDevices, copyAddr) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
@ -2063,10 +2030,8 @@ virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr)
|
||||
int ret = -1;
|
||||
|
||||
if (virAsprintf(&devName, "%.4x:%.2x:%.2x.%.1x", addr->domain,
|
||||
addr->bus, addr->slot, addr->function) < 0) {
|
||||
virReportOOMError();
|
||||
addr->bus, addr->slot, addr->function) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virPCIFile(&devPath, devName, "iommu_group") < 0)
|
||||
goto cleanup;
|
||||
@ -2125,10 +2090,8 @@ virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev)
|
||||
goto cleanup;
|
||||
}
|
||||
if (virAsprintf(&groupDev, "/dev/vfio/%s",
|
||||
last_component(groupPath)) < 0) {
|
||||
virReportOOMError();
|
||||
last_component(groupPath)) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
cleanup:
|
||||
VIR_FREE(devPath);
|
||||
VIR_FREE(groupPath);
|
||||
@ -2354,10 +2317,8 @@ virPCIGetDeviceAddressFromSysfsLink(const char *device_link,
|
||||
}
|
||||
|
||||
config_address = last_component(device_path);
|
||||
if (VIR_ALLOC(*bdf) != 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(*bdf) != 0)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (virPCIDeviceAddressParse(config_address, *bdf) != 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
@ -2460,7 +2421,6 @@ virPCIGetVirtualFunctions(const char *sysfs_path,
|
||||
|
||||
if (VIR_REALLOC_N(*virtual_functions,
|
||||
*num_virtual_functions + 1) < 0) {
|
||||
virReportOOMError();
|
||||
VIR_FREE(config_addr);
|
||||
goto error;
|
||||
}
|
||||
@ -2498,10 +2458,8 @@ virPCIIsVirtualFunction(const char *vf_sysfs_device_link)
|
||||
int ret = -1;
|
||||
|
||||
if (virAsprintf(&vf_sysfs_physfn_link, "%s/physfn",
|
||||
vf_sysfs_device_link) < 0) {
|
||||
virReportOOMError();
|
||||
vf_sysfs_device_link) < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = virFileExists(vf_sysfs_physfn_link);
|
||||
|
||||
@ -2562,27 +2520,17 @@ out:
|
||||
int
|
||||
virPCIGetSysfsFile(char *virPCIDeviceName, char **pci_sysfs_device_link)
|
||||
{
|
||||
if (virAsprintf(pci_sysfs_device_link, PCI_SYSFS "devices/%s",
|
||||
virPCIDeviceName) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return virAsprintf(pci_sysfs_device_link, PCI_SYSFS "devices/%s",
|
||||
virPCIDeviceName);
|
||||
}
|
||||
|
||||
int
|
||||
virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPtr dev,
|
||||
char **pci_sysfs_device_link)
|
||||
{
|
||||
if (virAsprintf(pci_sysfs_device_link,
|
||||
PCI_SYSFS "devices/%04x:%02x:%02x.%x", dev->domain,
|
||||
dev->bus, dev->slot, dev->function) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return virAsprintf(pci_sysfs_device_link,
|
||||
PCI_SYSFS "devices/%04x:%02x:%02x.%x", dev->domain,
|
||||
dev->bus, dev->slot, dev->function);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -86,7 +86,6 @@ virPortAllocatorPtr virPortAllocatorNew(unsigned short start,
|
||||
pa->end = end;
|
||||
|
||||
if (!(pa->bitmap = virBitmapNew((end-start)+1))) {
|
||||
virReportOOMError();
|
||||
virObjectUnref(pa);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -429,10 +429,8 @@ realloc:
|
||||
}
|
||||
|
||||
*map = virBitmapNew(maxcpu);
|
||||
if (!*map) {
|
||||
virReportOOMError();
|
||||
if (!*map)
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < maxcpu; i++)
|
||||
if (CPU_ISSET_S(i, masklen, mask))
|
||||
@ -476,10 +474,8 @@ int virProcessGetAffinity(pid_t pid ATTRIBUTE_UNUSED,
|
||||
virBitmapPtr *map,
|
||||
int maxcpu)
|
||||
{
|
||||
if (!(*map = virBitmapNew(maxcpu))) {
|
||||
virReportOOMError();
|
||||
if (!(*map = virBitmapNew(maxcpu)))
|
||||
return -1;
|
||||
}
|
||||
virBitmapSetAll(*map);
|
||||
|
||||
return 0;
|
||||
@ -524,15 +520,12 @@ int virProcessGetNamespaces(pid_t pid,
|
||||
|
||||
if (virAsprintf(&nsfile, "/proc/%llu/ns/%s",
|
||||
(unsigned long long)pid,
|
||||
ns[i]) < 0) {
|
||||
virReportOOMError();
|
||||
ns[i]) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((fd = open(nsfile, O_RDWR)) >= 0) {
|
||||
if (VIR_EXPAND_N(*fdlist, *nfdlist, 1) < 0) {
|
||||
VIR_FORCE_CLOSE(fd);
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -763,10 +756,8 @@ int virProcessGetStartTime(pid_t pid,
|
||||
char **tokens = NULL;
|
||||
|
||||
if (virAsprintf(&filename, "/proc/%llu/stat",
|
||||
(unsigned long long)pid) < 0) {
|
||||
virReportOOMError();
|
||||
(unsigned long long)pid) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((len = virFileReadAll(filename, 1024, &buf)) < 0)
|
||||
goto cleanup;
|
||||
|
@ -178,11 +178,6 @@ virRandomGenerateWWN(char **wwn,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (virAsprintf(wwn, "5" "%s%09llx", oui,
|
||||
(unsigned long long)virRandomBits(36)) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return virAsprintf(wwn, "5" "%s%09llx", oui,
|
||||
(unsigned long long)virRandomBits(36));
|
||||
}
|
||||
|
@ -117,10 +117,8 @@ virSCSIDeviceGetSgName(const char *adapter,
|
||||
|
||||
if (virAsprintf(&path,
|
||||
SYSFS_SCSI_DEVICES "/%d:%d:%d:%d/scsi_generic",
|
||||
adapter_id, bus, target, unit) < 0) {
|
||||
virReportOOMError();
|
||||
adapter_id, bus, target, unit) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(dir = opendir(path))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
@ -162,10 +160,8 @@ virSCSIDeviceGetDevName(const char *adapter,
|
||||
|
||||
if (virAsprintf(&path,
|
||||
SYSFS_SCSI_DEVICES "/%d:%d:%d:%d/block",
|
||||
adapter_id, bus, target, unit) < 0) {
|
||||
virReportOOMError();
|
||||
adapter_id, bus, target, unit) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(dir = opendir(path))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
@ -201,10 +197,8 @@ virSCSIDeviceNew(const char *adapter,
|
||||
char *vendor = NULL;
|
||||
char *model = NULL;
|
||||
|
||||
if (VIR_ALLOC(dev) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(dev) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dev->bus = bus;
|
||||
dev->target = target;
|
||||
@ -219,10 +213,8 @@ virSCSIDeviceNew(const char *adapter,
|
||||
|
||||
if (virAsprintf(&dev->name, "%d:%d:%d:%d", dev->adapter,
|
||||
dev->bus, dev->target, dev->unit) < 0 ||
|
||||
virAsprintf(&dev->sg_path, "/dev/%s", sg) < 0) {
|
||||
virReportOOMError();
|
||||
virAsprintf(&dev->sg_path, "/dev/%s", sg) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (access(dev->sg_path, F_OK) != 0) {
|
||||
virReportSystemError(errno,
|
||||
@ -234,10 +226,8 @@ virSCSIDeviceNew(const char *adapter,
|
||||
if (virAsprintf(&vendor_path,
|
||||
SYSFS_SCSI_DEVICES "/%s/vendor", dev->name) < 0 ||
|
||||
virAsprintf(&model_path,
|
||||
SYSFS_SCSI_DEVICES "/%s/model", dev->name) < 0) {
|
||||
virReportOOMError();
|
||||
SYSFS_SCSI_DEVICES "/%s/model", dev->name) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virFileReadAll(vendor_path, 1024, &vendor) < 0)
|
||||
goto cleanup;
|
||||
@ -248,10 +238,8 @@ virSCSIDeviceNew(const char *adapter,
|
||||
virTrimSpaces(vendor, NULL);
|
||||
virTrimSpaces(model, NULL);
|
||||
|
||||
if (virAsprintf(&dev->id, "%s:%s", vendor, model) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&dev->id, "%s:%s", vendor, model) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = dev;
|
||||
cleanup:
|
||||
@ -371,10 +359,8 @@ virSCSIDeviceListAdd(virSCSIDeviceListPtr list,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (VIR_REALLOC_N(list->devs, list->count + 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_REALLOC_N(list->devs, list->count + 1) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
list->devs[list->count++] = dev;
|
||||
|
||||
|
@ -48,10 +48,8 @@ sexpr_new(void)
|
||||
{
|
||||
struct sexpr *ret;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
}
|
||||
ret->kind = SEXPR_NIL;
|
||||
return ret;
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ virSocketAddrFormatFull(virSocketAddrPtr addr,
|
||||
if (withService) {
|
||||
if (virAsprintf(&addrstr, "127.0.0.1%s0",
|
||||
separator ? separator : ":") < 0)
|
||||
goto no_memory;
|
||||
goto error;
|
||||
} else {
|
||||
if (VIR_STRDUP(addrstr, "127.0.0.1") < 0)
|
||||
goto error;
|
||||
@ -311,7 +311,7 @@ virSocketAddrFormatFull(virSocketAddrPtr addr,
|
||||
|
||||
if (withService) {
|
||||
if (virAsprintf(&addrstr, "%s%s%s", host, separator, port) == -1)
|
||||
goto no_memory;
|
||||
goto error;
|
||||
} else {
|
||||
if (VIR_STRDUP(addrstr, host) < 0)
|
||||
goto error;
|
||||
@ -319,8 +319,6 @@ virSocketAddrFormatFull(virSocketAddrPtr addr,
|
||||
|
||||
return addrstr;
|
||||
|
||||
no_memory:
|
||||
virReportOOMError();
|
||||
error:
|
||||
return NULL;
|
||||
}
|
||||
|
@ -357,10 +357,8 @@ qcowXGetBackingStore(char **res,
|
||||
return BACKING_STORE_INVALID;
|
||||
if (size + 1 == 0)
|
||||
return BACKING_STORE_INVALID;
|
||||
if (VIR_ALLOC_N(*res, size + 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(*res, size + 1) < 0)
|
||||
return BACKING_STORE_ERROR;
|
||||
}
|
||||
memcpy(*res, buf + offset, size);
|
||||
(*res)[size] = '\0';
|
||||
|
||||
@ -444,10 +442,8 @@ vmdk4GetBackingStore(char **res,
|
||||
size_t len;
|
||||
int ret = BACKING_STORE_ERROR;
|
||||
|
||||
if (VIR_ALLOC_N(desc, STORAGE_MAX_HEAD + 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(desc, STORAGE_MAX_HEAD + 1) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
*res = NULL;
|
||||
/*
|
||||
@ -526,10 +522,8 @@ qedGetBackingStore(char **res,
|
||||
return BACKING_STORE_OK;
|
||||
if (offset + size > buf_size || offset + size < offset)
|
||||
return BACKING_STORE_INVALID;
|
||||
if (VIR_ALLOC_N(*res, size + 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(*res, size + 1) < 0)
|
||||
return BACKING_STORE_ERROR;
|
||||
}
|
||||
memcpy(*res, buf + offset, size);
|
||||
(*res)[size] = '\0';
|
||||
|
||||
@ -569,10 +563,8 @@ virFindBackingFile(const char *start, bool start_is_dir, const char *path,
|
||||
start = ".";
|
||||
d_len = 1;
|
||||
}
|
||||
if (virAsprintf(&combined, "%.*s/%s", (int)d_len, start, path) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&combined, "%.*s/%s", (int)d_len, start, path) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if (directory && !(*directory = mdir_name(combined))) {
|
||||
@ -737,10 +729,8 @@ qcow2GetFeatures(virBitmapPtr *features,
|
||||
if (len < QCOW2v3_HDR_SIZE)
|
||||
return -1;
|
||||
|
||||
if (!(feat = virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST))) {
|
||||
virReportOOMError();
|
||||
if (!(feat = virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST)))
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* todo: check for incompatible or autoclear features? */
|
||||
bits = virReadBufInt64BE(buf + QCOW2v3_HDR_FEATURES_COMPATIBLE);
|
||||
@ -771,10 +761,8 @@ virStorageFileGetMetadataInternal(const char *path,
|
||||
|
||||
VIR_DEBUG("path=%s, fd=%d, format=%d", path, fd, format);
|
||||
|
||||
if (VIR_ALLOC(meta) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(meta) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fstat(fd, &sb) < 0) {
|
||||
virReportSystemError(errno,
|
||||
@ -792,10 +780,8 @@ virStorageFileGetMetadataInternal(const char *path,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC_N(buf, len) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(buf, len) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((len = read(fd, buf, len)) < 0) {
|
||||
virReportSystemError(errno, _("cannot read header '%s'"), path);
|
||||
@ -940,10 +926,8 @@ virStorageFileProbeFormatFromFD(const char *path, int fd)
|
||||
return VIR_STORAGE_FILE_DIR;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC_N(head, len) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(head, len) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) == (off_t)-1) {
|
||||
virReportSystemError(errno, _("cannot set to start of '%s'"), path);
|
||||
|
@ -83,7 +83,7 @@ char **virStringSplit(const char *string,
|
||||
size_t len = tmp - remainder;
|
||||
|
||||
if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0)
|
||||
goto no_memory;
|
||||
goto error;
|
||||
|
||||
if (VIR_STRNDUP(tokens[ntokens], remainder, len) < 0)
|
||||
goto error;
|
||||
@ -94,7 +94,7 @@ char **virStringSplit(const char *string,
|
||||
}
|
||||
if (*string) {
|
||||
if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0)
|
||||
goto no_memory;
|
||||
goto error;
|
||||
|
||||
if (VIR_STRDUP(tokens[ntokens], remainder) < 0)
|
||||
goto error;
|
||||
@ -102,13 +102,11 @@ char **virStringSplit(const char *string,
|
||||
}
|
||||
|
||||
if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0)
|
||||
goto no_memory;
|
||||
goto error;
|
||||
tokens[ntokens++] = NULL;
|
||||
|
||||
return tokens;
|
||||
|
||||
no_memory:
|
||||
virReportOOMError();
|
||||
error:
|
||||
for (i = 0; i < ntokens; i++)
|
||||
VIR_FREE(tokens[i]);
|
||||
|
@ -305,10 +305,8 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
|
||||
eol = strchr(base, '\n');
|
||||
cur = strchr(base, ':') + 1;
|
||||
|
||||
if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0)
|
||||
goto error;
|
||||
}
|
||||
processor = &ret->processor[ret->nprocessor - 1];
|
||||
|
||||
virSkipSpaces(&cur);
|
||||
@ -435,10 +433,8 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
|
||||
while ((tmp_base = strstr(tmp_base, "processor "))
|
||||
&& (tmp_base = virSysinfoParseLine(tmp_base, "processor ",
|
||||
&procline))) {
|
||||
if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
processor = &ret->processor[ret->nprocessor - 1];
|
||||
if (VIR_STRDUP(processor->processor_manufacturer, manufacturer) < 0)
|
||||
goto cleanup;
|
||||
@ -843,25 +839,25 @@ virSysinfoRead(void) {
|
||||
goto cleanup;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
goto no_memory;
|
||||
goto error;
|
||||
|
||||
ret->type = VIR_SYSINFO_SMBIOS;
|
||||
|
||||
if (virSysinfoParseBIOS(outbuf, ret) < 0)
|
||||
goto no_memory;
|
||||
goto error;
|
||||
|
||||
if (virSysinfoParseSystem(outbuf, ret) < 0)
|
||||
goto no_memory;
|
||||
goto error;
|
||||
|
||||
ret->nprocessor = 0;
|
||||
ret->processor = NULL;
|
||||
if (virSysinfoParseProcessor(outbuf, ret) < 0)
|
||||
goto no_memory;
|
||||
goto error;
|
||||
|
||||
ret->nmemory = 0;
|
||||
ret->memory = NULL;
|
||||
if (virSysinfoParseMemory(outbuf, ret) < 0)
|
||||
goto no_memory;
|
||||
goto error;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(outbuf);
|
||||
@ -869,9 +865,7 @@ cleanup:
|
||||
|
||||
return ret;
|
||||
|
||||
no_memory:
|
||||
virReportOOMError();
|
||||
|
||||
error:
|
||||
virSysinfoDefFree(ret);
|
||||
ret = NULL;
|
||||
goto cleanup;
|
||||
|
@ -169,10 +169,8 @@ virThreadPoolPtr virThreadPoolNew(size_t minWorkers,
|
||||
if (minWorkers > maxWorkers)
|
||||
minWorkers = maxWorkers;
|
||||
|
||||
if (VIR_ALLOC(pool) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(pool) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pool->jobList.tail = pool->jobList.head = NULL;
|
||||
|
||||
@ -193,10 +191,8 @@ virThreadPoolPtr virThreadPoolNew(size_t minWorkers,
|
||||
pool->maxWorkers = maxWorkers;
|
||||
|
||||
for (i = 0; i < minWorkers; i++) {
|
||||
if (VIR_ALLOC(data) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(data) < 0)
|
||||
goto error;
|
||||
}
|
||||
data->pool = pool;
|
||||
data->cond = &pool->cond;
|
||||
|
||||
@ -216,10 +212,8 @@ virThreadPoolPtr virThreadPoolNew(size_t minWorkers,
|
||||
goto error;
|
||||
|
||||
for (i = 0; i < prioWorkers; i++) {
|
||||
if (VIR_ALLOC(data) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(data) < 0)
|
||||
goto error;
|
||||
}
|
||||
data->pool = pool;
|
||||
data->cond = &pool->prioCond;
|
||||
data->priority = true;
|
||||
@ -313,14 +307,11 @@ int virThreadPoolSendJob(virThreadPoolPtr pool,
|
||||
|
||||
if (pool->freeWorkers - pool->jobQueueDepth <= 0 &&
|
||||
pool->nWorkers < pool->maxWorkers) {
|
||||
if (VIR_EXPAND_N(pool->workers, pool->nWorkers, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_EXPAND_N(pool->workers, pool->nWorkers, 1) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(data) < 0) {
|
||||
pool->nWorkers--;
|
||||
virReportOOMError();
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -337,10 +328,8 @@ int virThreadPoolSendJob(virThreadPoolPtr pool,
|
||||
}
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(job) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(job) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
job->data = jobData;
|
||||
job->priority = priority;
|
||||
|
@ -303,10 +303,8 @@ char *virTimeStringNow(void)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (virTimeStringNowRaw(ret) < 0) {
|
||||
virReportSystemError(errno, "%s",
|
||||
@ -334,10 +332,8 @@ char *virTimeStringThen(unsigned long long when)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(ret, VIR_TIME_STRING_BUFLEN) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (virTimeStringThenRaw(when, ret) < 0) {
|
||||
virReportSystemError(errno, "%s",
|
||||
|
@ -47,10 +47,8 @@ virTPMCreateCancelPath(const char *devpath)
|
||||
if (dev) {
|
||||
dev++;
|
||||
if (virAsprintf(&path, "/sys/class/misc/%s/device/cancel",
|
||||
dev) < 0) {
|
||||
virReportOOMError();
|
||||
dev) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("TPM device path %s is invalid"), devpath);
|
||||
|
@ -137,36 +137,29 @@ virTypedParamsCheck(virTypedParameterPtr params,
|
||||
char *
|
||||
virTypedParameterToString(virTypedParameterPtr param)
|
||||
{
|
||||
char *value;
|
||||
int ret = -1;
|
||||
char *value = NULL;
|
||||
|
||||
switch (param->type) {
|
||||
case VIR_TYPED_PARAM_INT:
|
||||
if ((ret = virAsprintf(&value, "%d", param->value.i)) < 0)
|
||||
virReportOOMError();
|
||||
ignore_value(virAsprintf(&value, "%d", param->value.i));
|
||||
break;
|
||||
case VIR_TYPED_PARAM_UINT:
|
||||
if ((ret = virAsprintf(&value, "%u", param->value.ui)) < 0)
|
||||
virReportOOMError();
|
||||
ignore_value(virAsprintf(&value, "%u", param->value.ui));
|
||||
break;
|
||||
case VIR_TYPED_PARAM_LLONG:
|
||||
if ((ret = virAsprintf(&value, "%lld", param->value.l)) < 0)
|
||||
virReportOOMError();
|
||||
ignore_value(virAsprintf(&value, "%lld", param->value.l));
|
||||
break;
|
||||
case VIR_TYPED_PARAM_ULLONG:
|
||||
if ((ret = virAsprintf(&value, "%llu", param->value.ul)) < 0)
|
||||
virReportOOMError();
|
||||
ignore_value(virAsprintf(&value, "%llu", param->value.ul));
|
||||
break;
|
||||
case VIR_TYPED_PARAM_DOUBLE:
|
||||
if ((ret = virAsprintf(&value, "%g", param->value.d)) < 0)
|
||||
virReportOOMError();
|
||||
ignore_value(virAsprintf(&value, "%g", param->value.d));
|
||||
break;
|
||||
case VIR_TYPED_PARAM_BOOLEAN:
|
||||
if ((ret = virAsprintf(&value, "%d", param->value.b)) < 0)
|
||||
virReportOOMError();
|
||||
ignore_value(virAsprintf(&value, "%d", param->value.b));
|
||||
break;
|
||||
case VIR_TYPED_PARAM_STRING:
|
||||
ret = VIR_STRDUP(value, param->value.s);
|
||||
ignore_value(VIR_STRDUP(value, param->value.s));
|
||||
break;
|
||||
default:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
@ -174,10 +167,7 @@ virTypedParameterToString(virTypedParameterPtr param)
|
||||
param->type, param->field);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
return NULL;
|
||||
else
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
|
||||
/* Assign name, type, and the appropriately typed arg to param; in the
|
||||
@ -368,10 +358,8 @@ virTypedParamsReplaceString(virTypedParameterPtr *params,
|
||||
}
|
||||
old = param->value.s;
|
||||
} else {
|
||||
if (VIR_EXPAND_N(*params, n, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_EXPAND_N(*params, n, 1) < 0)
|
||||
goto error;
|
||||
}
|
||||
param = *params + n - 1;
|
||||
}
|
||||
|
||||
@ -406,10 +394,8 @@ virTypedParamsCopy(virTypedParameterPtr *dst,
|
||||
if (!src || nparams <= 0)
|
||||
return 0;
|
||||
|
||||
if (VIR_ALLOC_N(*dst, nparams) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(*dst, nparams) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < nparams; i++) {
|
||||
ignore_value(virStrcpyStatic((*dst)[i].field, src[i].field));
|
||||
@ -768,10 +754,8 @@ virTypedParamsAddInt(virTypedParameterPtr *params,
|
||||
virResetLastError();
|
||||
|
||||
VIR_TYPED_PARAM_CHECK();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0)
|
||||
goto error;
|
||||
}
|
||||
*maxparams = max;
|
||||
|
||||
if (virTypedParameterAssign(*params + n, name,
|
||||
@ -818,10 +802,8 @@ virTypedParamsAddUInt(virTypedParameterPtr *params,
|
||||
virResetLastError();
|
||||
|
||||
VIR_TYPED_PARAM_CHECK();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0)
|
||||
goto error;
|
||||
}
|
||||
*maxparams = max;
|
||||
|
||||
if (virTypedParameterAssign(*params + n, name,
|
||||
@ -868,10 +850,8 @@ virTypedParamsAddLLong(virTypedParameterPtr *params,
|
||||
virResetLastError();
|
||||
|
||||
VIR_TYPED_PARAM_CHECK();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0)
|
||||
goto error;
|
||||
}
|
||||
*maxparams = max;
|
||||
|
||||
if (virTypedParameterAssign(*params + n, name,
|
||||
@ -918,10 +898,8 @@ virTypedParamsAddULLong(virTypedParameterPtr *params,
|
||||
virResetLastError();
|
||||
|
||||
VIR_TYPED_PARAM_CHECK();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0)
|
||||
goto error;
|
||||
}
|
||||
*maxparams = max;
|
||||
|
||||
if (virTypedParameterAssign(*params + n, name,
|
||||
@ -968,10 +946,8 @@ virTypedParamsAddDouble(virTypedParameterPtr *params,
|
||||
virResetLastError();
|
||||
|
||||
VIR_TYPED_PARAM_CHECK();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0)
|
||||
goto error;
|
||||
}
|
||||
*maxparams = max;
|
||||
|
||||
if (virTypedParameterAssign(*params + n, name,
|
||||
@ -1018,10 +994,8 @@ virTypedParamsAddBoolean(virTypedParameterPtr *params,
|
||||
virResetLastError();
|
||||
|
||||
VIR_TYPED_PARAM_CHECK();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0)
|
||||
goto error;
|
||||
}
|
||||
*maxparams = max;
|
||||
|
||||
if (virTypedParameterAssign(*params + n, name,
|
||||
@ -1071,10 +1045,8 @@ virTypedParamsAddString(virTypedParameterPtr *params,
|
||||
virResetLastError();
|
||||
|
||||
VIR_TYPED_PARAM_CHECK();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0)
|
||||
goto error;
|
||||
}
|
||||
*maxparams = max;
|
||||
|
||||
if (VIR_STRDUP(str, value) < 0)
|
||||
@ -1131,10 +1103,8 @@ virTypedParamsAddFromString(virTypedParameterPtr *params,
|
||||
virResetLastError();
|
||||
|
||||
VIR_TYPED_PARAM_CHECK();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_RESIZE_N(*params, max, n, 1) < 0)
|
||||
goto error;
|
||||
}
|
||||
*maxparams = max;
|
||||
|
||||
if (virTypedParameterAssignFromStr(*params + n, name, type, value) < 0)
|
||||
|
@ -40,10 +40,8 @@ virURIParamAppend(virURIPtr uri,
|
||||
if (VIR_STRDUP(pname, name) < 0 || VIR_STRDUP(pvalue, value) < 0)
|
||||
goto error;
|
||||
|
||||
if (VIR_RESIZE_N(uri->params, uri->paramsAlloc, uri->paramsCount, 1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_RESIZE_N(uri->params, uri->paramsAlloc, uri->paramsCount, 1) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
uri->params[uri->paramsCount].name = pname;
|
||||
uri->params[uri->paramsCount].value = pvalue;
|
||||
@ -166,10 +164,8 @@ virURIParse(const char *uri)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(ret) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (VIR_STRDUP(ret->scheme, xmluri->scheme) < 0)
|
||||
goto error;
|
||||
@ -256,10 +252,8 @@ virURIFormat(virURIPtr uri)
|
||||
if (xmluri.server != NULL &&
|
||||
strchr(xmluri.server, ':') != NULL) {
|
||||
|
||||
if (virAsprintf(&tmpserver, "[%s]", xmluri.server) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&tmpserver, "[%s]", xmluri.server) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xmluri.server = tmpserver;
|
||||
}
|
||||
|
@ -96,10 +96,8 @@ static int virUSBSysReadFile(const char *f_name, const char *d_name,
|
||||
char *ignore = NULL;
|
||||
|
||||
tmp = virAsprintf(&filename, USB_SYSFS "/devices/%s/%s", d_name, f_name);
|
||||
if (tmp < 0) {
|
||||
virReportOOMError();
|
||||
if (tmp < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virFileReadAll(filename, 1024, &buf) < 0)
|
||||
goto cleanup;
|
||||
@ -334,10 +332,8 @@ virUSBDeviceNew(unsigned int bus,
|
||||
{
|
||||
virUSBDevicePtr dev;
|
||||
|
||||
if (VIR_ALLOC(dev) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC(dev) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dev->bus = bus;
|
||||
dev->dev = devno;
|
||||
@ -353,7 +349,6 @@ virUSBDeviceNew(unsigned int bus,
|
||||
if (virAsprintf(&dev->path, "%s" USB_DEVFS "%03d/%03d",
|
||||
vroot ? vroot : "",
|
||||
dev->bus, dev->dev) < 0) {
|
||||
virReportOOMError();
|
||||
virUSBDeviceFree(dev);
|
||||
return NULL;
|
||||
}
|
||||
@ -456,10 +451,8 @@ virUSBDeviceListAdd(virUSBDeviceListPtr list,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (VIR_REALLOC_N(list->devs, list->count+1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_REALLOC_N(list->devs, list->count+1) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
list->devs[list->count++] = dev;
|
||||
|
||||
|
@ -192,10 +192,8 @@ virPipeReadUntilEOF(int outfd, int errfd,
|
||||
|
||||
buf = ((fds[i].fd == outfd) ? outbuf : errbuf);
|
||||
size = (*buf ? strlen(*buf) : 0);
|
||||
if (VIR_REALLOC_N(*buf, size+got+1) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_REALLOC_N(*buf, size+got+1) < 0)
|
||||
goto error;
|
||||
}
|
||||
memmove(*buf+size, data, got);
|
||||
(*buf)[size+got] = '\0';
|
||||
}
|
||||
@ -549,10 +547,8 @@ char *virIndexToDiskName(int idx, const char *prefix)
|
||||
|
||||
offset = strlen(prefix);
|
||||
|
||||
if (VIR_ALLOC_N(name, offset + i + 1)) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(name, offset + i + 1))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy(name, prefix);
|
||||
name[offset + i] = '\0';
|
||||
@ -645,8 +641,6 @@ char *virGetHostname(void)
|
||||
freeaddrinfo(info);
|
||||
|
||||
cleanup:
|
||||
if (result == NULL)
|
||||
virReportOOMError();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -671,10 +665,8 @@ static char *virGetUserEnt(uid_t uid,
|
||||
if (val < 0)
|
||||
strbuflen = 1024;
|
||||
|
||||
if (VIR_ALLOC_N(strbuf, strbuflen) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(strbuf, strbuflen) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* From the manpage (terrifying but true):
|
||||
@ -684,11 +676,9 @@ static char *virGetUserEnt(uid_t uid,
|
||||
* The given name or uid was not found.
|
||||
*/
|
||||
while ((rc = getpwuid_r(uid, &pwbuf, strbuf, strbuflen, &pw)) == ERANGE) {
|
||||
if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0)
|
||||
VIR_FREE(strbuf);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (rc != 0 || pw == NULL) {
|
||||
virReportSystemError(rc,
|
||||
@ -718,10 +708,8 @@ static char *virGetGroupEnt(gid_t gid)
|
||||
if (val < 0)
|
||||
strbuflen = 1024;
|
||||
|
||||
if (VIR_ALLOC_N(strbuf, strbuflen) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(strbuf, strbuflen) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* From the manpage (terrifying but true):
|
||||
@ -732,7 +720,6 @@ static char *virGetGroupEnt(gid_t gid)
|
||||
*/
|
||||
while ((rc = getgrgid_r(gid, &grbuf, strbuf, strbuflen, &gr)) == ERANGE) {
|
||||
if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) {
|
||||
virReportOOMError();
|
||||
VIR_FREE(strbuf);
|
||||
return NULL;
|
||||
}
|
||||
@ -762,20 +749,14 @@ static char *virGetXDGDirectory(const char *xdgenvname, const char *xdgdefdir)
|
||||
char *home = NULL;
|
||||
|
||||
if (path && path[0]) {
|
||||
if (virAsprintf(&ret, "%s/libvirt", path) < 0)
|
||||
goto no_memory;
|
||||
ignore_value(virAsprintf(&ret, "%s/libvirt", path));
|
||||
} else {
|
||||
home = virGetUserEnt(geteuid(), VIR_USER_ENT_DIRECTORY);
|
||||
if (virAsprintf(&ret, "%s/%s/libvirt", home, xdgdefdir) < 0)
|
||||
goto no_memory;
|
||||
ignore_value(virAsprintf(&ret, "%s/%s/libvirt", home, xdgdefdir));
|
||||
}
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(home);
|
||||
return ret;
|
||||
no_memory:
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
char *virGetUserConfigDirectory(void)
|
||||
@ -797,11 +778,7 @@ char *virGetUserRuntimeDirectory(void)
|
||||
} else {
|
||||
char *ret;
|
||||
|
||||
if (virAsprintf(&ret, "%s/libvirt", path) < 0) {
|
||||
virReportOOMError();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ignore_value(virAsprintf(&ret, "%s/libvirt", path));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@ -834,16 +811,12 @@ virGetUserIDByName(const char *name, uid_t *uid)
|
||||
if (val < 0)
|
||||
strbuflen = 1024;
|
||||
|
||||
if (VIR_ALLOC_N(strbuf, strbuflen) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(strbuf, strbuflen) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
while ((rc = getpwnam_r(name, &pwbuf, strbuf, strbuflen, &pw)) == ERANGE) {
|
||||
if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pw) {
|
||||
@ -918,16 +891,12 @@ virGetGroupIDByName(const char *name, gid_t *gid)
|
||||
if (val < 0)
|
||||
strbuflen = 1024;
|
||||
|
||||
if (VIR_ALLOC_N(strbuf, strbuflen) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_ALLOC_N(strbuf, strbuflen) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
while ((rc = getgrnam_r(name, &grbuf, strbuf, strbuflen, &gr)) == ERANGE) {
|
||||
if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0) {
|
||||
virReportOOMError();
|
||||
if (VIR_RESIZE_N(strbuf, strbuflen, strbuflen, strbuflen) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
if (!gr) {
|
||||
@ -1015,14 +984,12 @@ virSetUIDGID(uid_t uid, gid_t gid)
|
||||
bufsize = 16384;
|
||||
|
||||
if (VIR_ALLOC_N(buf, bufsize) < 0) {
|
||||
virReportOOMError();
|
||||
err = ENOMEM;
|
||||
goto error;
|
||||
}
|
||||
while ((rc = getpwuid_r(uid, &pwd, buf, bufsize,
|
||||
&pwd_result)) == ERANGE) {
|
||||
if (VIR_RESIZE_N(buf, bufsize, bufsize, bufsize) < 0) {
|
||||
virReportOOMError();
|
||||
err = ENOMEM;
|
||||
goto error;
|
||||
}
|
||||
@ -1543,13 +1510,9 @@ virGetUnprivSGIOSysfsPath(const char *path,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (virAsprintf(&sysfs_path, "%s/%d:%d/queue/unpriv_sgio",
|
||||
sysfs_dir ? sysfs_dir : SYSFS_DEV_BLOCK_PATH,
|
||||
maj, min) < 0) {
|
||||
virReportOOMError();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ignore_value(virAsprintf(&sysfs_path, "%s/%d:%d/queue/unpriv_sgio",
|
||||
sysfs_dir ? sysfs_dir : SYSFS_DEV_BLOCK_PATH,
|
||||
maj, min));
|
||||
return sysfs_path;
|
||||
}
|
||||
|
||||
@ -1572,10 +1535,8 @@ virSetDeviceUnprivSGIO(const char *path,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virAsprintf(&val, "%d", unpriv_sgio) < 0) {
|
||||
virReportOOMError();
|
||||
if (virAsprintf(&val, "%d", unpriv_sgio) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((rc = virFileWriteStr(sysfs_path, val, 0)) < 0) {
|
||||
virReportSystemError(-rc, _("failed to set %s"), sysfs_path);
|
||||
@ -1656,10 +1617,8 @@ virReadFCHost(const char *sysfs_prefix,
|
||||
|
||||
if (virAsprintf(&sysfs_path, "%s/host%d/%s",
|
||||
sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH,
|
||||
host, entry) < 0) {
|
||||
virReportOOMError();
|
||||
host, entry) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virFileReadAll(sysfs_path, 1024, &buf) < 0)
|
||||
goto cleanup;
|
||||
@ -1691,10 +1650,8 @@ virIsCapableFCHost(const char *sysfs_prefix,
|
||||
|
||||
if (virAsprintf(&sysfs_path, "%s/host%d",
|
||||
sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH,
|
||||
host) < 0) {
|
||||
virReportOOMError();
|
||||
host) < 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (access(sysfs_path, F_OK) == 0)
|
||||
ret = true;
|
||||
@ -1715,19 +1672,15 @@ virIsCapableVport(const char *sysfs_prefix,
|
||||
"%s/host%d/%s",
|
||||
sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH,
|
||||
host,
|
||||
"vport_create") < 0) {
|
||||
virReportOOMError();
|
||||
"vport_create") < 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (virAsprintf(&scsi_host_path,
|
||||
"%s/host%d/%s",
|
||||
sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH,
|
||||
host,
|
||||
"vport_create") < 0) {
|
||||
virReportOOMError();
|
||||
"vport_create") < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((access(fc_host_path, F_OK) == 0) ||
|
||||
(access(scsi_host_path, F_OK) == 0))
|
||||
@ -1766,10 +1719,8 @@ virManageVport(const int parent_host,
|
||||
"%s/host%d/%s",
|
||||
SYSFS_FC_HOST_PATH,
|
||||
parent_host,
|
||||
operation_file) < 0) {
|
||||
virReportOOMError();
|
||||
operation_file) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!virFileExists(operation_path)) {
|
||||
VIR_FREE(operation_path);
|
||||
@ -1777,10 +1728,8 @@ virManageVport(const int parent_host,
|
||||
"%s/host%d/%s",
|
||||
SYSFS_SCSI_HOST_PATH,
|
||||
parent_host,
|
||||
operation_file) < 0) {
|
||||
virReportOOMError();
|
||||
operation_file) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!virFileExists(operation_path)) {
|
||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||
@ -1793,10 +1742,8 @@ virManageVport(const int parent_host,
|
||||
if (virAsprintf(&vport_name,
|
||||
"%s:%s",
|
||||
wwpn,
|
||||
wwnn) < 0) {
|
||||
virReportOOMError();
|
||||
wwnn) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virFileWriteStr(operation_path, vport_name, 0) == 0)
|
||||
ret = 0;
|
||||
@ -1856,10 +1803,8 @@ virGetFCHostNameByWWN(const char *sysfs_prefix,
|
||||
continue;
|
||||
|
||||
if (virAsprintf(&wwnn_path, "%s/%s/node_name", prefix,
|
||||
entry->d_name) < 0) {
|
||||
virReportOOMError();
|
||||
entry->d_name) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!virFileExists(wwnn_path)) {
|
||||
VIR_FREE(wwnn_path);
|
||||
@ -1875,10 +1820,8 @@ virGetFCHostNameByWWN(const char *sysfs_prefix,
|
||||
}
|
||||
|
||||
if (virAsprintf(&wwpn_path, "%s/%s/port_name", prefix,
|
||||
entry->d_name) < 0) {
|
||||
virReportOOMError();
|
||||
entry->d_name) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!virFileExists(wwpn_path)) {
|
||||
VIR_FREE(wwnn_buf);
|
||||
|
@ -607,7 +607,6 @@ virXPathNodeSet(const char *xpath,
|
||||
ret = obj->nodesetval->nodeNr;
|
||||
if (list != NULL && ret) {
|
||||
if (VIR_ALLOC_N(*list, ret) < 0) {
|
||||
virReportOOMError();
|
||||
ret = -1;
|
||||
} else {
|
||||
memcpy(*list, obj->nodesetval->nodeTab,
|
||||
|
Loading…
x
Reference in New Issue
Block a user