Replace all occurrences of
if (VIR_STRDUP(a, b) < 0)
/* effectively dead code */
with:
a = g_strdup(b);
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/lxc/lxc_conf.c | 21 ++++----------
src/lxc/lxc_container.c | 20 +++++--------
src/lxc/lxc_controller.c | 12 +++-----
src/lxc/lxc_driver.c | 3 +-
src/lxc/lxc_native.c | 63 +++++++++++++++-------------------------
src/lxc/lxc_process.c | 13 +++------
6 files changed, 46 insertions(+), 86 deletions(-)
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index 4d8314045e..de9793e523 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -150,10 +150,8 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
if (VIR_ALLOC(caps->host.secModels) < 0)
goto error;
caps->host.nsecModels = 1;
- if (VIR_STRDUP(caps->host.secModels[0].model, model) < 0)
- goto error;
- if (VIR_STRDUP(caps->host.secModels[0].doi, doi) < 0)
- goto error;
+ caps->host.secModels[0].model = g_strdup(model);
+ caps->host.secModels[0].doi = g_strdup(doi);
if (label &&
virCapabilitiesHostSecModelAddBaseLabel(&caps->host.secModels[0],
type,
@@ -233,19 +231,12 @@ virLXCDriverConfigNew(void)
cfg->securityRequireConfined = false;
/* Set the container configuration directory */
- if (VIR_STRDUP(cfg->configDir, LXC_CONFIG_DIR) < 0)
- goto error;
- if (VIR_STRDUP(cfg->stateDir, LXC_STATE_DIR) < 0)
- goto error;
- if (VIR_STRDUP(cfg->logDir, LXC_LOG_DIR) < 0)
- goto error;
- if (VIR_STRDUP(cfg->autostartDir, LXC_AUTOSTART_DIR) < 0)
- goto error;
+ cfg->configDir = g_strdup(LXC_CONFIG_DIR);
+ cfg->stateDir = g_strdup(LXC_STATE_DIR);
+ cfg->logDir = g_strdup(LXC_LOG_DIR);
+ cfg->autostartDir = g_strdup(LXC_AUTOSTART_DIR);
return cfg;
- error:
- virObjectUnref(cfg);
- return NULL;
}
int
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 5002356fe7..88dc2e2bdf 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -856,8 +856,9 @@ static int lxcContainerSetReadOnly(void)
lxcIsBasicMountLocation(mntent.mnt_dir))
continue;
- if (VIR_STRDUP(tmp, mntent.mnt_dir) < 0 ||
- VIR_APPEND_ELEMENT(mounts, nmounts, tmp) < 0) {
+ tmp = g_strdup(mntent.mnt_dir);
+
+ if (VIR_APPEND_ELEMENT(mounts, nmounts, tmp) < 0) {
VIR_FREE(tmp);
goto cleanup;
}
@@ -910,12 +911,10 @@ static int lxcContainerMountBasicFS(bool userns_enabled,
*/
if (userns_enabled && netns_disabled &&
STREQ(mnt->src, "sysfs")) {
- if (VIR_STRDUP(mnt_src, "/sys") < 0)
- goto cleanup;
+ mnt_src = g_strdup("/sys");
mnt_mflags = MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_RDONLY|MS_BIND;
} else {
- if (VIR_STRDUP(mnt_src, mnt->src) < 0)
- goto cleanup;
+ mnt_src = g_strdup(mnt->src);
mnt_mflags = mnt->mflags;
}
@@ -1292,8 +1291,7 @@ lxcContainerMountDetectFilesystem(const char *src, char **type)
goto cleanup;
}
- if (VIR_STRDUP(*type, data) < 0)
- goto cleanup;
+ *type = g_strdup(data);
done:
ret = 0;
@@ -1633,8 +1631,7 @@ int lxcContainerSetupHostdevCapsMakePath(const char *dev)
int ret = -1;
char *dir, *tmp;
- if (VIR_STRDUP(dir, dev) < 0)
- return -1;
+ dir = g_strdup(dev);
if ((tmp = strrchr(dir, '/'))) {
*tmp = '\0';
@@ -2166,8 +2163,7 @@ static int lxcContainerSetHostname(virDomainDefPtr def)
char *hostname = NULL;
/* Filter the VM name to get a valid hostname */
- if (VIR_STRDUP(name, def->name) < 0)
- goto cleanup;
+ name = g_strdup(def->name);
/* RFC 1123 allows 0-9 digits as a first character in hostname */
virStringFilterChars(name, hostname_validchars);
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 3c4e68524c..0c5b9e713d 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -172,8 +172,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name)
ctrl->timerShutdown = -1;
ctrl->firstClient = true;
- if (VIR_STRDUP(ctrl->name, name) < 0)
- goto error;
+ ctrl->name = g_strdup(name);
if (!(caps = virLXCDriverCapsInit(NULL)))
goto error;
@@ -1643,8 +1642,7 @@ virLXCControllerSetupHostdevCapsStorage(virDomainDefPtr vmDef,
goto cleanup;
}
- if (VIR_STRDUP(path, dev) < 0)
- goto cleanup;
+ path = g_strdup(dev);
while (*(path + len) == '/')
len++;
@@ -1722,8 +1720,7 @@ virLXCControllerSetupHostdevCapsMisc(virDomainDefPtr vmDef,
goto cleanup;
}
- if (VIR_STRDUP(path, dev) < 0)
- goto cleanup;
+ path = g_strdup(dev);
while (*(path + len) == '/')
len++;
@@ -2534,8 +2531,7 @@ int main(int argc, char *argv[])
case 'v':
if (VIR_REALLOC_N(veths, nveths+1) < 0)
goto cleanup;
- if (VIR_STRDUP(veths[nveths++], optarg) < 0)
- goto cleanup;
+ veths[nveths++] = g_strdup(optarg);
break;
case 'c':
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 65d17aba8e..41a6a446bd 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -617,8 +617,7 @@ static char *lxcDomainGetOSType(virDomainPtr dom)
if (virDomainGetOSTypeEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
- if (VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type)) < 0)
- goto cleanup;
+ ret = g_strdup(virDomainOSTypeToString(vm->def->os.type));
cleanup:
virDomainObjEndAPI(&vm);
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 8ae3c7b006..5df09a849e 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -64,18 +64,13 @@ lxcCreateFSDef(int type,
def->type = type;
def->accessmode = VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH;
- if (src && VIR_STRDUP(def->src->path, src) < 0)
- goto error;
- if (VIR_STRDUP(def->dst, dst) < 0)
- goto error;
+ if (src)
+ def->src->path = g_strdup(src);
+ def->dst = g_strdup(dst);
def->readonly = readonly;
def->usage = usage;
return def;
-
- error:
- virDomainFSDefFree(def);
- return NULL;
}
typedef struct _lxcFstab lxcFstab;
@@ -113,8 +108,7 @@ static char ** lxcStringSplit(const char *string)
char **parts;
char **result = NULL;
- if (VIR_STRDUP(tmp, string) < 0)
- return NULL;
+ tmp = g_strdup(string);
/* Replace potential \t by a space */
for (i = 0; tmp[i]; i++) {
@@ -136,8 +130,7 @@ static char ** lxcStringSplit(const char *string)
if (VIR_EXPAND_N(result, ntokens, 1) < 0)
goto error;
- if (VIR_STRDUP(result[ntokens-2], parts[i]) < 0)
- goto error;
+ result[ntokens - 2] = g_strdup(parts[i]);
}
VIR_FREE(tmp);
@@ -166,11 +159,10 @@ lxcParseFstabLine(char *fstabLine)
if (!parts[0] || !parts[1] || !parts[2] || !parts[3])
goto error;
- if (VIR_STRDUP(fstab->src, parts[0]) < 0 ||
- VIR_STRDUP(fstab->dst, parts[1]) < 0 ||
- VIR_STRDUP(fstab->type, parts[2]) < 0 ||
- VIR_STRDUP(fstab->options, parts[3]) < 0)
- goto error;
+ fstab->src = g_strdup(parts[0]);
+ fstab->dst = g_strdup(parts[1]);
+ fstab->type = g_strdup(parts[2]);
+ fstab->options = g_strdup(parts[3]);
virStringListFree(parts);
@@ -276,8 +268,7 @@ lxcAddFstabLine(virDomainDefPtr def, lxcFstabPtr fstab)
if (virAsprintf(&dst, "/%s", fstab->dst) < 0)
goto cleanup;
} else {
- if (VIR_STRDUP(dst, fstab->dst) < 0)
- goto cleanup;
+ dst = g_strdup(fstab->dst);
}
/* Check that we don't add basic mounts */
@@ -367,8 +358,7 @@ lxcCreateNetDef(const char *type,
else
net->linkstate = VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN;
- if (VIR_STRDUP(net->ifname_guest, name) < 0)
- goto error;
+ net->ifname_guest = g_strdup(name);
if (mac && virMacAddrParse(mac, &macAddr) == 0)
net->mac = macAddr;
@@ -376,17 +366,18 @@ lxcCreateNetDef(const char *type,
if (STREQ(type, "veth")) {
if (linkdev) {
net->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
- if (VIR_STRDUP(net->data.bridge.brname, linkdev) < 0)
- goto error;
+ net->data.bridge.brname = g_strdup(linkdev);
} else {
net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
}
} else if (STREQ(type, "macvlan")) {
net->type = VIR_DOMAIN_NET_TYPE_DIRECT;
- if (!linkdev || VIR_STRDUP(net->data.direct.linkdev, linkdev) < 0)
+ if (!linkdev)
goto error;
+ net->data.direct.linkdev = g_strdup(linkdev);
+
if (!macvlanmode || STREQ(macvlanmode, "private"))
net->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_PRIVATE;
else if (STREQ(macvlanmode, "vepa"))
@@ -415,11 +406,8 @@ lxcCreateHostdevDef(int mode, int type, const char *data)
hostdev->mode = mode;
hostdev->source.caps.type = type;
- if (type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET &&
- VIR_STRDUP(hostdev->source.caps.u.net.ifname, data) < 0) {
- virDomainHostdevDefFree(hostdev);
- hostdev = NULL;
- }
+ if (type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET)
+ hostdev->source.caps.u.net.ifname = g_strdup(data);
return hostdev;
}
@@ -451,12 +439,9 @@ lxcAddNetworkRouteDefinition(const char *address,
char *familyStr = NULL;
char *zero = NULL;
- if (VIR_STRDUP(zero, family == AF_INET ? VIR_SOCKET_ADDR_IPV4_ALL
- : VIR_SOCKET_ADDR_IPV6_ALL) < 0)
- goto error;
+ zero = g_strdup(family == AF_INET ? VIR_SOCKET_ADDR_IPV4_ALL :
VIR_SOCKET_ADDR_IPV6_ALL);
- if (VIR_STRDUP(familyStr, family == AF_INET ? "ipv4" : "ipv6")
< 0)
- goto error;
+ familyStr = g_strdup(family == AF_INET ? "ipv4" : "ipv6");
if (!(route = virNetDevIPRouteCreate(_("Domain interface"), familyStr,
zero, NULL, address, 0, false,
@@ -1123,8 +1108,7 @@ lxcParseConfigString(const char *config,
VIR_FREE(value);
}
- if (VIR_STRDUP(vmdef->os.init, "/sbin/init") < 0)
- goto error;
+ vmdef->os.init = g_strdup("/sbin/init");
if (virConfGetValueString(properties, "lxc.uts.name", &value) <= 0)
{
virResetLastError();
@@ -1134,11 +1118,10 @@ lxcParseConfigString(const char *config,
goto error;
}
- if (VIR_STRDUP(vmdef->name, value) < 0)
- goto error;
+ vmdef->name = g_strdup(value);
- if (!vmdef->name && (VIR_STRDUP(vmdef->name, "unnamed") <
0))
- goto error;
+ if (!vmdef->name)
+ vmdef->name = g_strdup("unnamed");
if (lxcSetRootfs(vmdef, properties) < 0)
goto error;
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index d9939f102d..450053d163 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -628,8 +628,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
(*veths)[i] = veth;
- if (VIR_STRDUP(def->nets[i]->ifname_guest_actual, veth) < 0)
- goto cleanup;
+ def->nets[i]->ifname_guest_actual = g_strdup(veth);
/* Make sure all net definitions will have a name in the container */
if (!net->ifname_guest) {
@@ -1156,9 +1155,8 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm)
root->type = VIR_DOMAIN_FS_TYPE_MOUNT;
- if (VIR_STRDUP(root->src->path, "/") < 0 ||
- VIR_STRDUP(root->dst, "/") < 0)
- goto error;
+ root->src->path = g_strdup("/");
+ root->dst = g_strdup("/");
if (VIR_INSERT_ELEMENT(vm->def->fss,
0,
@@ -1266,10 +1264,7 @@ int virLXCProcessStart(virConnectPtr conn,
if (VIR_ALLOC(res) < 0)
goto cleanup;
- if (VIR_STRDUP(res->partition, "/machine") < 0) {
- VIR_FREE(res);
- goto cleanup;
- }
+ res->partition = g_strdup("/machine");
vm->def->resource = res;
}
--
2.21.0