From nobody Mon Feb 9 07:21:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571576193; cv=none; d=zoho.com; s=zohoarc; b=mSNeTZVTxi5Ber0EXbb7YhgdDk/ipoErpOHqpKYso4s/qkQgO0HcRMFEpORzZaIYHtbHAOBkMpOTRWBXUfc2m8QLk8/KIwzzWf1gW6Gs/vF8eM5qpQyAxqScq7WL54jeFwrxDwleIvcp/LJhjA+EcvgOuDC94FVD/yBSAufgO1Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571576193; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Uw6vlVp7KfPUbXL3muaiN36dfKs/QHInKzHesy8ZweI=; b=LmGeELHmuRD3T4M8KwhDnV41yDvQbld/jPHF6r+TGBCYlVzsZhzz/6ClJ/nhHKeR3nH6KU4XAM79738WuuTN8u/ODWAx4rAqUnQhq2LLJ/W+bLQxMMwKAELYhBVUVzcgQThC55s/uwbRGQd7wTSxsIg3bUh5zXJtG/4a7eHe6lY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 15715761936471004.3788182977007; Sun, 20 Oct 2019 05:56:33 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-164-AA8LJuWiPsixCjDFyEeqhQ-1; Sun, 20 Oct 2019 08:56:29 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6483D107AD35; Sun, 20 Oct 2019 12:56:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 408FF9473; Sun, 20 Oct 2019 12:56:18 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0863F4EE70; Sun, 20 Oct 2019 12:56:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9KCttV3023485 for ; Sun, 20 Oct 2019 08:55:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 517FE3CC8; Sun, 20 Oct 2019 12:55:55 +0000 (UTC) Received: from lpt.redhat.com (ovpn-200-23.brq.redhat.com [10.40.200.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1D309446 for ; Sun, 20 Oct 2019 12:55:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571576192; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Uw6vlVp7KfPUbXL3muaiN36dfKs/QHInKzHesy8ZweI=; b=OlNEQz7lpu9XBhGbNuXceSq6uVNrwFj19+A5csFqLN1SbTWWH7oG3mqcimvHdP03Pq7E9q agv8azcUXPfHMjDCU0KwsXvdbv2dagiChiOfZ4E/GJHg5erARUGSftB6qBkBCHvNDHc3FG GhNYMwNNuei5kHPWxaMShbl2JtYunow= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Sun, 20 Oct 2019 14:55:36 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 18/34] lxc: use g_strdup instead of VIR_STRDUP X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: AA8LJuWiPsixCjDFyEeqhQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Replace all occurrences of if (VIR_STRDUP(a, b) < 0) /* effectively dead code */ with: a =3D g_strdup(b); Signed-off-by: J=C3=A1n Tomko --- 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 =3D 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 =3D g_strdup(model); + caps->host.secModels[0].doi =3D g_strdup(doi); if (label && virCapabilitiesHostSecModelAddBaseLabel(&caps->host.secModels[= 0], type, @@ -233,19 +231,12 @@ virLXCDriverConfigNew(void) cfg->securityRequireConfined =3D false; =20 /* 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 =3D g_strdup(LXC_CONFIG_DIR); + cfg->stateDir =3D g_strdup(LXC_STATE_DIR); + cfg->logDir =3D g_strdup(LXC_LOG_DIR); + cfg->autostartDir =3D g_strdup(LXC_AUTOSTART_DIR); =20 return cfg; - error: - virObjectUnref(cfg); - return NULL; } =20 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; =20 - if (VIR_STRDUP(tmp, mntent.mnt_dir) < 0 || - VIR_APPEND_ELEMENT(mounts, nmounts, tmp) < 0) { + tmp =3D 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_enabl= ed, */ if (userns_enabled && netns_disabled && STREQ(mnt->src, "sysfs")) { - if (VIR_STRDUP(mnt_src, "/sys") < 0) - goto cleanup; + mnt_src =3D g_strdup("/sys"); mnt_mflags =3D MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_RDONLY|MS_BIND; } else { - if (VIR_STRDUP(mnt_src, mnt->src) < 0) - goto cleanup; + mnt_src =3D g_strdup(mnt->src); mnt_mflags =3D mnt->mflags; } =20 @@ -1292,8 +1291,7 @@ lxcContainerMountDetectFilesystem(const char *src, ch= ar **type) goto cleanup; } =20 - if (VIR_STRDUP(*type, data) < 0) - goto cleanup; + *type =3D g_strdup(data); =20 done: ret =3D 0; @@ -1633,8 +1631,7 @@ int lxcContainerSetupHostdevCapsMakePath(const char *= dev) int ret =3D -1; char *dir, *tmp; =20 - if (VIR_STRDUP(dir, dev) < 0) - return -1; + dir =3D g_strdup(dev); =20 if ((tmp =3D strrchr(dir, '/'))) { *tmp =3D '\0'; @@ -2166,8 +2163,7 @@ static int lxcContainerSetHostname(virDomainDefPtr de= f) char *hostname =3D NULL; =20 /* Filter the VM name to get a valid hostname */ - if (VIR_STRDUP(name, def->name) < 0) - goto cleanup; + name =3D g_strdup(def->name); =20 /* 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 ch= ar *name) ctrl->timerShutdown =3D -1; ctrl->firstClient =3D true; =20 - if (VIR_STRDUP(ctrl->name, name) < 0) - goto error; + ctrl->name =3D g_strdup(name); =20 if (!(caps =3D virLXCDriverCapsInit(NULL))) goto error; @@ -1643,8 +1642,7 @@ virLXCControllerSetupHostdevCapsStorage(virDomainDefP= tr vmDef, goto cleanup; } =20 - if (VIR_STRDUP(path, dev) < 0) - goto cleanup; + path =3D g_strdup(dev); =20 while (*(path + len) =3D=3D '/') len++; @@ -1722,8 +1720,7 @@ virLXCControllerSetupHostdevCapsMisc(virDomainDefPtr = vmDef, goto cleanup; } =20 - if (VIR_STRDUP(path, dev) < 0) - goto cleanup; + path =3D g_strdup(dev); =20 while (*(path + len) =3D=3D '/') 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++] =3D g_strdup(optarg); break; =20 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; =20 - if (VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type)) < 0) - goto cleanup; + ret =3D g_strdup(virDomainOSTypeToString(vm->def->os.type)); =20 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, =20 def->type =3D type; def->accessmode =3D 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 =3D g_strdup(src); + def->dst =3D g_strdup(dst); def->readonly =3D readonly; def->usage =3D usage; =20 return def; - - error: - virDomainFSDefFree(def); - return NULL; } =20 typedef struct _lxcFstab lxcFstab; @@ -113,8 +108,7 @@ static char ** lxcStringSplit(const char *string) char **parts; char **result =3D NULL; =20 - if (VIR_STRDUP(tmp, string) < 0) - return NULL; + tmp =3D g_strdup(string); =20 /* Replace potential \t by a space */ for (i =3D 0; tmp[i]; i++) { @@ -136,8 +130,7 @@ static char ** lxcStringSplit(const char *string) if (VIR_EXPAND_N(result, ntokens, 1) < 0) goto error; =20 - if (VIR_STRDUP(result[ntokens-2], parts[i]) < 0) - goto error; + result[ntokens - 2] =3D g_strdup(parts[i]); } =20 VIR_FREE(tmp); @@ -166,11 +159,10 @@ lxcParseFstabLine(char *fstabLine) if (!parts[0] || !parts[1] || !parts[2] || !parts[3]) goto error; =20 - 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 =3D g_strdup(parts[0]); + fstab->dst =3D g_strdup(parts[1]); + fstab->type =3D g_strdup(parts[2]); + fstab->options =3D g_strdup(parts[3]); =20 virStringListFree(parts); =20 @@ -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 =3D g_strdup(fstab->dst); } =20 /* Check that we don't add basic mounts */ @@ -367,8 +358,7 @@ lxcCreateNetDef(const char *type, else net->linkstate =3D VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN; =20 - if (VIR_STRDUP(net->ifname_guest, name) < 0) - goto error; + net->ifname_guest =3D g_strdup(name); =20 if (mac && virMacAddrParse(mac, &macAddr) =3D=3D 0) net->mac =3D macAddr; @@ -376,17 +366,18 @@ lxcCreateNetDef(const char *type, if (STREQ(type, "veth")) { if (linkdev) { net->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; - if (VIR_STRDUP(net->data.bridge.brname, linkdev) < 0) - goto error; + net->data.bridge.brname =3D g_strdup(linkdev); } else { net->type =3D VIR_DOMAIN_NET_TYPE_ETHERNET; } } else if (STREQ(type, "macvlan")) { net->type =3D VIR_DOMAIN_NET_TYPE_DIRECT; =20 - if (!linkdev || VIR_STRDUP(net->data.direct.linkdev, linkdev) < 0) + if (!linkdev) goto error; =20 + net->data.direct.linkdev =3D g_strdup(linkdev); + if (!macvlanmode || STREQ(macvlanmode, "private")) net->data.direct.mode =3D VIR_NETDEV_MACVLAN_MODE_PRIVATE; else if (STREQ(macvlanmode, "vepa")) @@ -415,11 +406,8 @@ lxcCreateHostdevDef(int mode, int type, const char *da= ta) hostdev->mode =3D mode; hostdev->source.caps.type =3D type; =20 - if (type =3D=3D VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET && - VIR_STRDUP(hostdev->source.caps.u.net.ifname, data) < 0) { - virDomainHostdevDefFree(hostdev); - hostdev =3D NULL; - } + if (type =3D=3D VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET) + hostdev->source.caps.u.net.ifname =3D g_strdup(data); =20 return hostdev; } @@ -451,12 +439,9 @@ lxcAddNetworkRouteDefinition(const char *address, char *familyStr =3D NULL; char *zero =3D NULL; =20 - if (VIR_STRDUP(zero, family =3D=3D AF_INET ? VIR_SOCKET_ADDR_IPV4_ALL - : VIR_SOCKET_ADDR_IPV6_ALL) < 0) - goto error; + zero =3D g_strdup(family =3D=3D AF_INET ? VIR_SOCKET_ADDR_IPV4_ALL : V= IR_SOCKET_ADDR_IPV6_ALL); =20 - if (VIR_STRDUP(familyStr, family =3D=3D AF_INET ? "ipv4" : "ipv6") < 0) - goto error; + familyStr =3D g_strdup(family =3D=3D AF_INET ? "ipv4" : "ipv6"); =20 if (!(route =3D virNetDevIPRouteCreate(_("Domain interface"), familySt= r, zero, NULL, address, 0, false, @@ -1123,8 +1108,7 @@ lxcParseConfigString(const char *config, VIR_FREE(value); } =20 - if (VIR_STRDUP(vmdef->os.init, "/sbin/init") < 0) - goto error; + vmdef->os.init =3D g_strdup("/sbin/init"); =20 if (virConfGetValueString(properties, "lxc.uts.name", &value) <=3D 0) { virResetLastError(); @@ -1134,11 +1118,10 @@ lxcParseConfigString(const char *config, goto error; } =20 - if (VIR_STRDUP(vmdef->name, value) < 0) - goto error; + vmdef->name =3D g_strdup(value); =20 - if (!vmdef->name && (VIR_STRDUP(vmdef->name, "unnamed") < 0)) - goto error; + if (!vmdef->name) + vmdef->name =3D g_strdup("unnamed"); =20 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 c= onn, =20 (*veths)[i] =3D veth; =20 - if (VIR_STRDUP(def->nets[i]->ifname_guest_actual, veth) < 0) - goto cleanup; + def->nets[i]->ifname_guest_actual =3D g_strdup(veth); =20 /* Make sure all net definitions will have a name in the container= */ if (!net->ifname_guest) { @@ -1156,9 +1155,8 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm) =20 root->type =3D VIR_DOMAIN_FS_TYPE_MOUNT; =20 - if (VIR_STRDUP(root->src->path, "/") < 0 || - VIR_STRDUP(root->dst, "/") < 0) - goto error; + root->src->path =3D g_strdup("/"); + root->dst =3D g_strdup("/"); =20 if (VIR_INSERT_ELEMENT(vm->def->fss, 0, @@ -1266,10 +1264,7 @@ int virLXCProcessStart(virConnectPtr conn, if (VIR_ALLOC(res) < 0) goto cleanup; =20 - if (VIR_STRDUP(res->partition, "/machine") < 0) { - VIR_FREE(res); - goto cleanup; - } + res->partition =3D g_strdup("/machine"); =20 vm->def->resource =3D res; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list