From nobody Sun Feb 8 17:21:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1536551328817246.37764571369974; Sun, 9 Sep 2018 20:48:48 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 9EB9BC050005; Mon, 10 Sep 2018 03:48:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5D15619487; Mon, 10 Sep 2018 03:48:46 +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 093C9181A13C; Mon, 10 Sep 2018 03:48:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8A3m8va021353 for ; Sun, 9 Sep 2018 23:48:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 018185C1B5; Mon, 10 Sep 2018 03:48:08 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED5FB5C1B4 for ; Mon, 10 Sep 2018 03:48:04 +0000 (UTC) Received: from m50211.mail.qiye.163.com (m50211.mail.qiye.163.com [123.125.50.211]) by mx1.redhat.com (Postfix) with ESMTP id CEB154E021 for ; Mon, 10 Sep 2018 03:48:01 +0000 (UTC) Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp3 (Coremail) with SMTP id PdOowEDZhkJu6ZVb8BUdAg--.502S7; Mon, 10 Sep 2018 11:48:00 +0800 (CST) From: Shi Lei To: libvir-list@redhat.com Date: Mon, 10 Sep 2018 11:47:54 +0800 Message-Id: <20180910034755.31246-6-shi_lei@massclouds.com> In-Reply-To: <20180910034755.31246-1-shi_lei@massclouds.com> References: <20180910034755.31246-1-shi_lei@massclouds.com> X-CM-TRANSID: PdOowEDZhkJu6ZVb8BUdAg--.502S7 X-Coremail-Antispam: 1Uf129KBjvJXoWxJw1DXF4DKw45Cw18Xw1rtFb_yoW5GF1rpa 43GFyDtr9aqFyxArZ7Jw1fCF98Z3yqgF4jgryjg3Z8Zan8Cw1S9FW7KryS9F95Gry8Gr1f X3ZYgF95uFWvyrUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pE4lksUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbifhC9T1rpNNMxsgAAsL X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 212 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 10 Sep 2018 03:48:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 10 Sep 2018 03:48:03 +0000 (UTC) for IP:'123.125.50.211' DOMAIN:'m50211.mail.qiye.163.com' HELO:'m50211.mail.qiye.163.com' FROM:'shi_lei@massclouds.com' RCPT:'' X-RedHat-Spam-Score: -0.01 (RCVD_IN_DNSWL_NONE) 123.125.50.211 m50211.mail.qiye.163.com 123.125.50.211 m50211.mail.qiye.163.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/6] phyp: driver: use VIR_AUTOCLOSE instead of VIR_FORCE_CLOSE 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 10 Sep 2018 03:48:47 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOCLOSE mac= ro, many of the VIR_FORCE_CLOSE calls can be dropped, which in turn leads to getting rid of many of our cleanup sections. =20 Signed-off-by: Shi Lei --- src/phyp/phyp_driver.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 28a1fa3..c813fac 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -463,37 +463,33 @@ phypUUIDTable_WriteFile(virConnectPtr conn) phyp_driverPtr phyp_driver =3D conn->privateData; uuid_tablePtr uuid_table =3D phyp_driver->uuid_table; size_t i =3D 0; - int fd =3D -1; char local_file[] =3D "./uuid_table"; + VIR_AUTOCLOSE(fd); =20 if ((fd =3D creat(local_file, 0755)) =3D=3D -1) - goto err; + return -1; =20 for (i =3D 0; i < uuid_table->nlpars; i++) { if (safewrite(fd, &uuid_table->lpars[i]->id, sizeof(uuid_table->lpars[i]->id)) !=3D sizeof(uuid_table->lpars[i]->id)) { VIR_ERROR(_("Unable to write information to local file.")); - goto err; + return -1; } =20 if (safewrite(fd, uuid_table->lpars[i]->uuid, VIR_UUID_BUFLEN) != =3D VIR_UUID_BUFLEN) { VIR_ERROR(_("Unable to write information to local file.")); - goto err; + return -1; } } =20 if (VIR_CLOSE(fd) < 0) { virReportSystemError(errno, _("Could not close %s"), local_file); - goto err; + return -1; } return 0; - - err: - VIR_FORCE_CLOSE(fd); - return -1; } =20 static int @@ -641,14 +637,14 @@ phypUUIDTable_ReadFile(virConnectPtr conn) phyp_driverPtr phyp_driver =3D conn->privateData; uuid_tablePtr uuid_table =3D phyp_driver->uuid_table; size_t i =3D 0; - int fd =3D -1; char local_file[] =3D "./uuid_table"; int rc =3D 0; int id; + VIR_AUTOCLOSE(fd); =20 if ((fd =3D open(local_file, O_RDONLY)) =3D=3D -1) { VIR_WARN("Unable to read information from local file."); - goto err; + return -1; } =20 /* Creating a new data base and writing to local file */ @@ -658,28 +654,23 @@ phypUUIDTable_ReadFile(virConnectPtr conn) rc =3D read(fd, &id, sizeof(int)); if (rc =3D=3D sizeof(int)) { if (VIR_ALLOC(uuid_table->lpars[i]) < 0) - goto err; + return -1; uuid_table->lpars[i]->id =3D id; } else { VIR_WARN ("Unable to read from information from local file."); - goto err; + return -1; } =20 rc =3D read(fd, uuid_table->lpars[i]->uuid, VIR_UUID_BUFLEN); if (rc !=3D VIR_UUID_BUFLEN) { VIR_WARN("Unable to read information from local file."); - goto err; + return -1; } } } =20 - VIR_FORCE_CLOSE(fd); return 0; - - err: - VIR_FORCE_CLOSE(fd); - return -1; } =20 static int --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list