From nobody Sun Feb 8 23:03:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1582517438; cv=none; d=zohomail.com; s=zohoarc; b=Rh8F71bgXWRn1N1uD8eTWS5Hkm4OAiWZNFvp5FsicLqSwSRAQYuzQP2hPqeT34+cO0VF645jiXb5KcmS6L6XVyHZp8zjv38rnZ8dyiuAIbX+tsCB12Yksto9R5yP8duncrg/OU4dzgu+wYklzCplHAX7q5L9FpVWPsuO0MLXQOE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582517438; h=Content-Type:Content-Transfer-Encoding:Cc: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=NEzyGFnFGJhU2DqYENBZi2U3oA1MQXU+0z5gPDoFLxA=; b=mA4zAG4DH6R7cmE32kISaEdsCdqH9jmY06K2sEN6ABSbmaDES+GWj27GgXFYyFaN3fBJgpsYujyCY+3nWTA5zOgKWGqvVrrz1UmRZEokY2Y6LbsAEVEYIbkw/2Fmn2anmAoMXxA9yLdn8FtFSEDC6tpfP5GS+TY/ZKAtQXd9mKU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1582517438533371.265172612137; Sun, 23 Feb 2020 20:10:38 -0800 (PST) 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-323-BMP2dMfxPWWzyF71VYcw_Q-1; Sun, 23 Feb 2020 23:10:35 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B94428017DF; Mon, 24 Feb 2020 04:10:29 +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 8F8A81001B2D; Mon, 24 Feb 2020 04:10:29 +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 48A6E860E7; Mon, 24 Feb 2020 04:10:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01O4ARsg015594 for ; Sun, 23 Feb 2020 23:10:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id D324710EE6CD; Mon, 24 Feb 2020 04:10:27 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CDECD10EE6CC for ; Mon, 24 Feb 2020 04:10:25 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8F3D2185A790 for ; Mon, 24 Feb 2020 04:10:25 +0000 (UTC) Received: from mail-qv1-f66.google.com (mail-qv1-f66.google.com [209.85.219.66]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-374-4T_8GKfYOFCMpKaVZguq0Q-1; Sun, 23 Feb 2020 23:10:23 -0500 Received: by mail-qv1-f66.google.com with SMTP id q9so3610357qvu.7 for ; Sun, 23 Feb 2020 20:10:23 -0800 (PST) Received: from localhost.localdomain ([191.254.236.241]) by smtp.gmail.com with ESMTPSA id p126sm5355658qkd.108.2020.02.23.20.10.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Feb 2020 20:10:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582517437; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=NEzyGFnFGJhU2DqYENBZi2U3oA1MQXU+0z5gPDoFLxA=; b=BKwzpgOUPwGRzpwx1IFpTFpuxiWi0UlhXD6+jR1mIJA2e9QYs5yjCecXXLn6TVO7AHqrzK qCVkULmUOnIGpkx5MoYFAS6QAZdpYzV9gEbjyxmXx9U+5KVnNgQSNfzjmRWNiOcwfI3uw8 aqZQCxG6FqbKHLqMgt+C3ZiFieifxSA= X-MC-Unique: BMP2dMfxPWWzyF71VYcw_Q-1 X-MC-Unique: 4T_8GKfYOFCMpKaVZguq0Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Kzp07a7vm7Sic0fCCsvaEUeW1Fs/MioMoDp+nfun45U=; b=YQKVjohLyHV7gFxm0Ij8g7V7Od7DojE2YJsOj28s8yb2TTcJN050kCbY0h8imRLbRc U1599Ha4/zGeE2O2TpWJcpxVAOpDwvaikaUMFR1U4s78hGStjKNqZKdsaX0ij0tilBOO TemXDBgKCbh93u2+ousJsEzG+fFrx9Pfy8CuIxjwTzrU12FWeXo1YXfmLuOZRo095O9N DoXFfFGZGZITyrWUWfpFNoxmMKiVQ6OJFDaDUmqh6deBkPZH6tjwPoIKYOINoKjZ4vs+ ri9ZzOpQSgicdDunJ5wUWh4JNoDDkQLhCCGnexQNdmOLfIygY5aP4J3x0rPMR6pmSyRS QfRA== X-Gm-Message-State: APjAAAU+eA9JS+b1Kxd5aXKYseUHVUzzXh4b9f48VwgbUvpw5OsyZCBf 12hBvEa9h1xUK3VcO35pFYCyTf1s X-Google-Smtp-Source: APXvYqyHkFdP4h6tclFbG8kLMOHh6b3QpDkYX2nDUBhrC/w6IKOGnN4Wl+n9NLfGuaiE7Mm3mLmp2A== X-Received: by 2002:ad4:4e73:: with SMTP id ec19mr40155029qvb.78.1582517422325; Sun, 23 Feb 2020 20:10:22 -0800 (PST) From: Julio Faracco To: libvir-list@redhat.com Subject: [PATCH v3 3/5] lxc: Replacing default strings definitions by g_autofree statement. Date: Mon, 24 Feb 2020 01:09:43 -0300 Message-Id: <20200224040942.17695-4-jcfaracco@gmail.com> In-Reply-To: <20200224040942.17695-1-jcfaracco@gmail.com> References: <20200224040942.17695-1-jcfaracco@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01O4ARsg015594 X-loop: libvir-list@redhat.com Cc: danielhb413@gmail.com 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.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There are a lots of strings being handled inside some LXC functions. They can be moved to g_autofree to avoid declaring a return value to get proper code cleanups. This commit is changing functions from lxc_{controller,cgroup,fuse} only. Signed-off-by: Julio Faracco --- src/lxc/lxc_cgroup.c | 15 +++---- src/lxc/lxc_controller.c | 96 ++++++++++++++-------------------------- src/lxc/lxc_fuse.c | 23 +++------- 3 files changed, 44 insertions(+), 90 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 997a5c3dfa..d29b65092a 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -54,8 +54,7 @@ static int virLXCCgroupSetupCpusetTune(virDomainDefPtr de= f, virCgroupPtr cgroup, virBitmapPtr nodemask) { - int ret =3D -1; - char *mask =3D NULL; + g_autofree char *mask =3D NULL; virDomainNumatuneMemMode mode; =20 if (def->placement_mode !=3D VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO && @@ -66,21 +65,17 @@ static int virLXCCgroupSetupCpusetTune(virDomainDefPtr = def, =20 if (virDomainNumatuneGetMode(def->numa, -1, &mode) < 0 || mode =3D=3D VIR_DOMAIN_NUMATUNE_MEM_STRICT) { - ret =3D 0; - goto cleanup; + return 0; } =20 if (virDomainNumatuneMaybeFormatNodeset(def->numa, nodemask, &mask, -1) < 0) - goto cleanup; + return -1; =20 if (mask && virCgroupSetCpusetMems(cgroup, mask) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - VIR_FREE(mask); - return ret; + return 0; } =20 =20 diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 518967ee83..c580b17f5f 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -802,8 +802,7 @@ static int virLXCControllerGetNumadAdvice(virLXCControl= lerPtr ctrl, virBitmapPtr *mask) { virBitmapPtr nodemask =3D NULL; - char *nodeset =3D NULL; - int ret =3D -1; + g_autofree char *nodeset =3D NULL; =20 /* Get the advisory nodeset from numad if 'placement' of * either or is 'auto'. @@ -812,20 +811,17 @@ static int virLXCControllerGetNumadAdvice(virLXCContr= ollerPtr ctrl, nodeset =3D virNumaGetAutoPlacementAdvice(virDomainDefGetVcpus(ctr= l->def), ctrl->def->mem.cur_balloon= ); if (!nodeset) - goto cleanup; + return -1; =20 VIR_DEBUG("Nodeset returned from numad: %s", nodeset); =20 if (virBitmapParse(nodeset, &nodemask, VIR_DOMAIN_CPUMASK_LEN) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; *mask =3D nodemask; =20 - cleanup: - VIR_FREE(nodeset); - return ret; + return 0; } =20 =20 @@ -1434,9 +1430,8 @@ virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr= map, */ static int virLXCControllerSetupUserns(virLXCControllerPtr ctrl) { - char *uid_map =3D NULL; - char *gid_map =3D NULL; - int ret =3D -1; + g_autofree char *uid_map =3D NULL; + g_autofree char *gid_map =3D NULL; =20 /* User namespace is disabled for container */ if (ctrl->def->idmap.nuidmap =3D=3D 0) { @@ -1450,28 +1445,23 @@ static int virLXCControllerSetupUserns(virLXCContro= llerPtr ctrl) if (virLXCControllerSetupUsernsMap(ctrl->def->idmap.uidmap, ctrl->def->idmap.nuidmap, uid_map) < 0) - goto cleanup; + return -1; =20 gid_map =3D g_strdup_printf("/proc/%d/gid_map", ctrl->initpid); =20 if (virLXCControllerSetupUsernsMap(ctrl->def->idmap.gidmap, ctrl->def->idmap.ngidmap, gid_map) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - VIR_FREE(uid_map); - VIR_FREE(gid_map); - return ret; + return 0; } =20 static int virLXCControllerSetupDev(virLXCControllerPtr ctrl) { - char *mount_options =3D NULL; - char *opts =3D NULL; - char *dev =3D NULL; - int ret =3D -1; + g_autofree char *mount_options =3D NULL; + g_autofree char *opts =3D NULL; + g_autofree char *dev =3D NULL; =20 VIR_DEBUG("Setting up /dev/ for container"); =20 @@ -1488,24 +1478,18 @@ static int virLXCControllerSetupDev(virLXCControlle= rPtr ctrl) opts =3D g_strdup_printf("mode=3D755,size=3D65536%s", mount_options); =20 if (virFileSetupDev(dev, opts) < 0) - goto cleanup; + return -1; =20 if (lxcContainerChown(ctrl->def, dev) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - VIR_FREE(opts); - VIR_FREE(mount_options); - VIR_FREE(dev); - return ret; + return 0; } =20 static int virLXCControllerPopulateDevices(virLXCControllerPtr ctrl) { size_t i; - int ret =3D -1; - char *path =3D NULL; + g_autofree char *path =3D NULL; const struct { int maj; int min; @@ -1521,7 +1505,7 @@ static int virLXCControllerPopulateDevices(virLXCCont= rollerPtr ctrl) }; =20 if (virLXCControllerSetupDev(ctrl) < 0) - goto cleanup; + return -1; =20 /* Populate /dev/ with a few important bits */ for (i =3D 0; i < G_N_ELEMENTS(devs); i++) { @@ -1534,19 +1518,14 @@ static int virLXCControllerPopulateDevices(virLXCCo= ntrollerPtr ctrl) virReportSystemError(errno, _("Failed to make device %s"), path); - goto cleanup; + return -1; } =20 if (lxcContainerChown(ctrl->def, path) < 0) - goto cleanup; - - VIR_FREE(path); + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - return ret; + return 0; } =20 =20 @@ -2202,10 +2181,9 @@ virLXCControllerSetupPrivateNS(void) static int virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl) { - char *mount_options =3D NULL; - char *opts =3D NULL; - char *devpts =3D NULL; - int ret =3D -1; + g_autofree char *mount_options =3D NULL; + g_autofree char *opts =3D NULL; + g_autofree char *devpts =3D NULL; gid_t ptsgid =3D 5; =20 VIR_DEBUG("Setting up private /dev/pts"); @@ -2220,7 +2198,7 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl) virReportSystemError(errno, _("Failed to make path %s"), devpts); - goto cleanup; + return -1; } =20 if (ctrl->def->idmap.ngidmap) @@ -2239,26 +2217,20 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctr= l) virReportSystemError(errno, _("Failed to mount devpts on %s"), devpts); - goto cleanup; + return -1; } =20 if (access(ctrl->devptmx, R_OK) < 0) { virReportSystemError(ENOSYS, "%s", _("Kernel does not support private devpts")); - goto cleanup; + return -1; } =20 if ((lxcContainerChown(ctrl->def, ctrl->devptmx) < 0) || (lxcContainerChown(ctrl->def, devpts) < 0)) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(opts); - VIR_FREE(devpts); - VIR_FREE(mount_options); - return ret; + return 0; } =20 =20 @@ -2279,8 +2251,7 @@ virLXCControllerSetupConsoles(virLXCControllerPtr ctr= l, char **containerTTYPaths) { size_t i; - int ret =3D -1; - char *ttyHostPath =3D NULL; + g_autofree char *ttyHostPath =3D NULL; =20 for (i =3D 0; i < ctrl->nconsoles; i++) { VIR_DEBUG("Opening tty on private %s", ctrl->devptmx); @@ -2289,20 +2260,17 @@ virLXCControllerSetupConsoles(virLXCControllerPtr c= trl, &containerTTYPaths[i], &ttyHostPath) < 0) { virReportSystemError(errno, "%s", _("Failed to allocate tty")); - goto cleanup; + return -1; } =20 /* Change the owner of tty device to the root user of container */ if (lxcContainerChown(ctrl->def, ttyHostPath) < 0) - goto cleanup; + return -1; =20 VIR_FREE(ttyHostPath); } =20 - ret =3D 0; - cleanup: - VIR_FREE(ttyHostPath); - return ret; + return 0; } =20 =20 diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c index 44f240a0b5..8cfccdd7e0 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -40,8 +40,7 @@ static const char *fuse_meminfo_path =3D "/meminfo"; =20 static int lxcProcGetattr(const char *path, struct stat *stbuf) { - int res; - char *mempath =3D NULL; + g_autofree char *mempath =3D NULL; struct stat sb; struct fuse_context *context =3D fuse_get_context(); virDomainDefPtr def =3D (virDomainDefPtr)context->private_data; @@ -49,16 +48,12 @@ static int lxcProcGetattr(const char *path, struct stat= *stbuf) memset(stbuf, 0, sizeof(struct stat)); mempath =3D g_strdup_printf("/proc/%s", path); =20 - res =3D 0; - if (STREQ(path, "/")) { stbuf->st_mode =3D S_IFDIR | 0755; stbuf->st_nlink =3D 2; } else if (STREQ(path, fuse_meminfo_path)) { - if (stat(mempath, &sb) < 0) { - res =3D -errno; - goto cleanup; - } + if (stat(mempath, &sb) < 0) + return -errno; =20 stbuf->st_uid =3D def->idmap.uidmap ? def->idmap.uidmap[0].target = : 0; stbuf->st_gid =3D def->idmap.gidmap ? def->idmap.gidmap[0].target = : 0; @@ -71,12 +66,10 @@ static int lxcProcGetattr(const char *path, struct stat= *stbuf) stbuf->st_ctime =3D sb.st_ctime; stbuf->st_mtime =3D sb.st_mtime; } else { - res =3D -ENOENT; + return -ENOENT; } =20 - cleanup: - VIR_FREE(mempath); - return res; + return 0; } =20 static int lxcProcReaddir(const char *path, void *buf, @@ -127,7 +120,7 @@ static int lxcProcReadMeminfo(char *hostpath, virDomain= DefPtr def, { int res; FILE *fd =3D NULL; - char *line =3D NULL; + g_autofree char *line =3D NULL; size_t n; struct virLXCMeminfo meminfo; virBuffer buffer =3D VIR_BUFFER_INITIALIZER; @@ -229,7 +222,6 @@ static int lxcProcReadMeminfo(char *hostpath, virDomain= DefPtr def, memcpy(buf, virBufferCurrentContent(new_meminfo), res); =20 cleanup: - VIR_FREE(line); virBufferFreeAndReset(new_meminfo); VIR_FORCE_FCLOSE(fd); return res; @@ -242,7 +234,7 @@ static int lxcProcRead(const char *path G_GNUC_UNUSED, struct fuse_file_info *fi G_GNUC_UNUSED) { int res =3D -ENOENT; - char *hostpath =3D NULL; + g_autofree char *hostpath =3D NULL; struct fuse_context *context =3D NULL; virDomainDefPtr def =3D NULL; =20 @@ -256,7 +248,6 @@ static int lxcProcRead(const char *path G_GNUC_UNUSED, res =3D lxcProcHostRead(hostpath, buf, size, offset); } =20 - VIR_FREE(hostpath); return res; } =20 --=20 2.20.1