lxc: use g_strdup instead of VIR_STRDUP

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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2019-10-20 13:49:46 +02:00
parent 620cd4d0c8
commit 380bc1bec7
6 changed files with 46 additions and 86 deletions

View File

@ -150,10 +150,8 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
if (VIR_ALLOC(caps->host.secModels) < 0) if (VIR_ALLOC(caps->host.secModels) < 0)
goto error; goto error;
caps->host.nsecModels = 1; caps->host.nsecModels = 1;
if (VIR_STRDUP(caps->host.secModels[0].model, model) < 0) caps->host.secModels[0].model = g_strdup(model);
goto error; caps->host.secModels[0].doi = g_strdup(doi);
if (VIR_STRDUP(caps->host.secModels[0].doi, doi) < 0)
goto error;
if (label && if (label &&
virCapabilitiesHostSecModelAddBaseLabel(&caps->host.secModels[0], virCapabilitiesHostSecModelAddBaseLabel(&caps->host.secModels[0],
type, type,
@ -233,19 +231,12 @@ virLXCDriverConfigNew(void)
cfg->securityRequireConfined = false; cfg->securityRequireConfined = false;
/* Set the container configuration directory */ /* Set the container configuration directory */
if (VIR_STRDUP(cfg->configDir, LXC_CONFIG_DIR) < 0) cfg->configDir = g_strdup(LXC_CONFIG_DIR);
goto error; cfg->stateDir = g_strdup(LXC_STATE_DIR);
if (VIR_STRDUP(cfg->stateDir, LXC_STATE_DIR) < 0) cfg->logDir = g_strdup(LXC_LOG_DIR);
goto error; cfg->autostartDir = g_strdup(LXC_AUTOSTART_DIR);
if (VIR_STRDUP(cfg->logDir, LXC_LOG_DIR) < 0)
goto error;
if (VIR_STRDUP(cfg->autostartDir, LXC_AUTOSTART_DIR) < 0)
goto error;
return cfg; return cfg;
error:
virObjectUnref(cfg);
return NULL;
} }
int int

View File

@ -856,8 +856,9 @@ static int lxcContainerSetReadOnly(void)
lxcIsBasicMountLocation(mntent.mnt_dir)) lxcIsBasicMountLocation(mntent.mnt_dir))
continue; continue;
if (VIR_STRDUP(tmp, mntent.mnt_dir) < 0 || tmp = g_strdup(mntent.mnt_dir);
VIR_APPEND_ELEMENT(mounts, nmounts, tmp) < 0) {
if (VIR_APPEND_ELEMENT(mounts, nmounts, tmp) < 0) {
VIR_FREE(tmp); VIR_FREE(tmp);
goto cleanup; goto cleanup;
} }
@ -910,12 +911,10 @@ static int lxcContainerMountBasicFS(bool userns_enabled,
*/ */
if (userns_enabled && netns_disabled && if (userns_enabled && netns_disabled &&
STREQ(mnt->src, "sysfs")) { STREQ(mnt->src, "sysfs")) {
if (VIR_STRDUP(mnt_src, "/sys") < 0) mnt_src = g_strdup("/sys");
goto cleanup;
mnt_mflags = MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_RDONLY|MS_BIND; mnt_mflags = MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_RDONLY|MS_BIND;
} else { } else {
if (VIR_STRDUP(mnt_src, mnt->src) < 0) mnt_src = g_strdup(mnt->src);
goto cleanup;
mnt_mflags = mnt->mflags; mnt_mflags = mnt->mflags;
} }
@ -1292,8 +1291,7 @@ lxcContainerMountDetectFilesystem(const char *src, char **type)
goto cleanup; goto cleanup;
} }
if (VIR_STRDUP(*type, data) < 0) *type = g_strdup(data);
goto cleanup;
done: done:
ret = 0; ret = 0;
@ -1633,8 +1631,7 @@ int lxcContainerSetupHostdevCapsMakePath(const char *dev)
int ret = -1; int ret = -1;
char *dir, *tmp; char *dir, *tmp;
if (VIR_STRDUP(dir, dev) < 0) dir = g_strdup(dev);
return -1;
if ((tmp = strrchr(dir, '/'))) { if ((tmp = strrchr(dir, '/'))) {
*tmp = '\0'; *tmp = '\0';
@ -2166,8 +2163,7 @@ static int lxcContainerSetHostname(virDomainDefPtr def)
char *hostname = NULL; char *hostname = NULL;
/* Filter the VM name to get a valid hostname */ /* Filter the VM name to get a valid hostname */
if (VIR_STRDUP(name, def->name) < 0) name = g_strdup(def->name);
goto cleanup;
/* RFC 1123 allows 0-9 digits as a first character in hostname */ /* RFC 1123 allows 0-9 digits as a first character in hostname */
virStringFilterChars(name, hostname_validchars); virStringFilterChars(name, hostname_validchars);

View File

@ -172,8 +172,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name)
ctrl->timerShutdown = -1; ctrl->timerShutdown = -1;
ctrl->firstClient = true; ctrl->firstClient = true;
if (VIR_STRDUP(ctrl->name, name) < 0) ctrl->name = g_strdup(name);
goto error;
if (!(caps = virLXCDriverCapsInit(NULL))) if (!(caps = virLXCDriverCapsInit(NULL)))
goto error; goto error;
@ -1643,8 +1642,7 @@ virLXCControllerSetupHostdevCapsStorage(virDomainDefPtr vmDef,
goto cleanup; goto cleanup;
} }
if (VIR_STRDUP(path, dev) < 0) path = g_strdup(dev);
goto cleanup;
while (*(path + len) == '/') while (*(path + len) == '/')
len++; len++;
@ -1722,8 +1720,7 @@ virLXCControllerSetupHostdevCapsMisc(virDomainDefPtr vmDef,
goto cleanup; goto cleanup;
} }
if (VIR_STRDUP(path, dev) < 0) path = g_strdup(dev);
goto cleanup;
while (*(path + len) == '/') while (*(path + len) == '/')
len++; len++;
@ -2534,8 +2531,7 @@ int main(int argc, char *argv[])
case 'v': case 'v':
if (VIR_REALLOC_N(veths, nveths+1) < 0) if (VIR_REALLOC_N(veths, nveths+1) < 0)
goto cleanup; goto cleanup;
if (VIR_STRDUP(veths[nveths++], optarg) < 0) veths[nveths++] = g_strdup(optarg);
goto cleanup;
break; break;
case 'c': case 'c':

View File

@ -617,8 +617,7 @@ static char *lxcDomainGetOSType(virDomainPtr dom)
if (virDomainGetOSTypeEnsureACL(dom->conn, vm->def) < 0) if (virDomainGetOSTypeEnsureACL(dom->conn, vm->def) < 0)
goto cleanup; goto cleanup;
if (VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type)) < 0) ret = g_strdup(virDomainOSTypeToString(vm->def->os.type));
goto cleanup;
cleanup: cleanup:
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);

View File

@ -64,18 +64,13 @@ lxcCreateFSDef(int type,
def->type = type; def->type = type;
def->accessmode = VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH; def->accessmode = VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH;
if (src && VIR_STRDUP(def->src->path, src) < 0) if (src)
goto error; def->src->path = g_strdup(src);
if (VIR_STRDUP(def->dst, dst) < 0) def->dst = g_strdup(dst);
goto error;
def->readonly = readonly; def->readonly = readonly;
def->usage = usage; def->usage = usage;
return def; return def;
error:
virDomainFSDefFree(def);
return NULL;
} }
typedef struct _lxcFstab lxcFstab; typedef struct _lxcFstab lxcFstab;
@ -113,8 +108,7 @@ static char ** lxcStringSplit(const char *string)
char **parts; char **parts;
char **result = NULL; char **result = NULL;
if (VIR_STRDUP(tmp, string) < 0) tmp = g_strdup(string);
return NULL;
/* Replace potential \t by a space */ /* Replace potential \t by a space */
for (i = 0; tmp[i]; i++) { for (i = 0; tmp[i]; i++) {
@ -136,8 +130,7 @@ static char ** lxcStringSplit(const char *string)
if (VIR_EXPAND_N(result, ntokens, 1) < 0) if (VIR_EXPAND_N(result, ntokens, 1) < 0)
goto error; goto error;
if (VIR_STRDUP(result[ntokens-2], parts[i]) < 0) result[ntokens - 2] = g_strdup(parts[i]);
goto error;
} }
VIR_FREE(tmp); VIR_FREE(tmp);
@ -166,11 +159,10 @@ lxcParseFstabLine(char *fstabLine)
if (!parts[0] || !parts[1] || !parts[2] || !parts[3]) if (!parts[0] || !parts[1] || !parts[2] || !parts[3])
goto error; goto error;
if (VIR_STRDUP(fstab->src, parts[0]) < 0 || fstab->src = g_strdup(parts[0]);
VIR_STRDUP(fstab->dst, parts[1]) < 0 || fstab->dst = g_strdup(parts[1]);
VIR_STRDUP(fstab->type, parts[2]) < 0 || fstab->type = g_strdup(parts[2]);
VIR_STRDUP(fstab->options, parts[3]) < 0) fstab->options = g_strdup(parts[3]);
goto error;
virStringListFree(parts); virStringListFree(parts);
@ -276,8 +268,7 @@ lxcAddFstabLine(virDomainDefPtr def, lxcFstabPtr fstab)
if (virAsprintf(&dst, "/%s", fstab->dst) < 0) if (virAsprintf(&dst, "/%s", fstab->dst) < 0)
goto cleanup; goto cleanup;
} else { } else {
if (VIR_STRDUP(dst, fstab->dst) < 0) dst = g_strdup(fstab->dst);
goto cleanup;
} }
/* Check that we don't add basic mounts */ /* Check that we don't add basic mounts */
@ -367,8 +358,7 @@ lxcCreateNetDef(const char *type,
else else
net->linkstate = VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN; net->linkstate = VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN;
if (VIR_STRDUP(net->ifname_guest, name) < 0) net->ifname_guest = g_strdup(name);
goto error;
if (mac && virMacAddrParse(mac, &macAddr) == 0) if (mac && virMacAddrParse(mac, &macAddr) == 0)
net->mac = macAddr; net->mac = macAddr;
@ -376,17 +366,18 @@ lxcCreateNetDef(const char *type,
if (STREQ(type, "veth")) { if (STREQ(type, "veth")) {
if (linkdev) { if (linkdev) {
net->type = VIR_DOMAIN_NET_TYPE_BRIDGE; net->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
if (VIR_STRDUP(net->data.bridge.brname, linkdev) < 0) net->data.bridge.brname = g_strdup(linkdev);
goto error;
} else { } else {
net->type = VIR_DOMAIN_NET_TYPE_ETHERNET; net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
} }
} else if (STREQ(type, "macvlan")) { } else if (STREQ(type, "macvlan")) {
net->type = VIR_DOMAIN_NET_TYPE_DIRECT; net->type = VIR_DOMAIN_NET_TYPE_DIRECT;
if (!linkdev || VIR_STRDUP(net->data.direct.linkdev, linkdev) < 0) if (!linkdev)
goto error; goto error;
net->data.direct.linkdev = g_strdup(linkdev);
if (!macvlanmode || STREQ(macvlanmode, "private")) if (!macvlanmode || STREQ(macvlanmode, "private"))
net->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_PRIVATE; net->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_PRIVATE;
else if (STREQ(macvlanmode, "vepa")) else if (STREQ(macvlanmode, "vepa"))
@ -415,11 +406,8 @@ lxcCreateHostdevDef(int mode, int type, const char *data)
hostdev->mode = mode; hostdev->mode = mode;
hostdev->source.caps.type = type; hostdev->source.caps.type = type;
if (type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET && if (type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET)
VIR_STRDUP(hostdev->source.caps.u.net.ifname, data) < 0) { hostdev->source.caps.u.net.ifname = g_strdup(data);
virDomainHostdevDefFree(hostdev);
hostdev = NULL;
}
return hostdev; return hostdev;
} }
@ -451,12 +439,9 @@ lxcAddNetworkRouteDefinition(const char *address,
char *familyStr = NULL; char *familyStr = NULL;
char *zero = NULL; char *zero = NULL;
if (VIR_STRDUP(zero, family == AF_INET ? VIR_SOCKET_ADDR_IPV4_ALL zero = g_strdup(family == AF_INET ? VIR_SOCKET_ADDR_IPV4_ALL : VIR_SOCKET_ADDR_IPV6_ALL);
: VIR_SOCKET_ADDR_IPV6_ALL) < 0)
goto error;
if (VIR_STRDUP(familyStr, family == AF_INET ? "ipv4" : "ipv6") < 0) familyStr = g_strdup(family == AF_INET ? "ipv4" : "ipv6");
goto error;
if (!(route = virNetDevIPRouteCreate(_("Domain interface"), familyStr, if (!(route = virNetDevIPRouteCreate(_("Domain interface"), familyStr,
zero, NULL, address, 0, false, zero, NULL, address, 0, false,
@ -1123,8 +1108,7 @@ lxcParseConfigString(const char *config,
VIR_FREE(value); VIR_FREE(value);
} }
if (VIR_STRDUP(vmdef->os.init, "/sbin/init") < 0) vmdef->os.init = g_strdup("/sbin/init");
goto error;
if (virConfGetValueString(properties, "lxc.uts.name", &value) <= 0) { if (virConfGetValueString(properties, "lxc.uts.name", &value) <= 0) {
virResetLastError(); virResetLastError();
@ -1134,11 +1118,10 @@ lxcParseConfigString(const char *config,
goto error; goto error;
} }
if (VIR_STRDUP(vmdef->name, value) < 0) vmdef->name = g_strdup(value);
goto error;
if (!vmdef->name && (VIR_STRDUP(vmdef->name, "unnamed") < 0)) if (!vmdef->name)
goto error; vmdef->name = g_strdup("unnamed");
if (lxcSetRootfs(vmdef, properties) < 0) if (lxcSetRootfs(vmdef, properties) < 0)
goto error; goto error;

View File

@ -628,8 +628,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
(*veths)[i] = veth; (*veths)[i] = veth;
if (VIR_STRDUP(def->nets[i]->ifname_guest_actual, veth) < 0) def->nets[i]->ifname_guest_actual = g_strdup(veth);
goto cleanup;
/* Make sure all net definitions will have a name in the container */ /* Make sure all net definitions will have a name in the container */
if (!net->ifname_guest) { if (!net->ifname_guest) {
@ -1156,9 +1155,8 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm)
root->type = VIR_DOMAIN_FS_TYPE_MOUNT; root->type = VIR_DOMAIN_FS_TYPE_MOUNT;
if (VIR_STRDUP(root->src->path, "/") < 0 || root->src->path = g_strdup("/");
VIR_STRDUP(root->dst, "/") < 0) root->dst = g_strdup("/");
goto error;
if (VIR_INSERT_ELEMENT(vm->def->fss, if (VIR_INSERT_ELEMENT(vm->def->fss,
0, 0,
@ -1266,10 +1264,7 @@ int virLXCProcessStart(virConnectPtr conn,
if (VIR_ALLOC(res) < 0) if (VIR_ALLOC(res) < 0)
goto cleanup; goto cleanup;
if (VIR_STRDUP(res->partition, "/machine") < 0) { res->partition = g_strdup("/machine");
VIR_FREE(res);
goto cleanup;
}
vm->def->resource = res; vm->def->resource = res;
} }