From nobody Sat Feb 7 09:36:38 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 1536551296518561.2219453275595; Sun, 9 Sep 2018 20:48:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B97CC05D3EE; Mon, 10 Sep 2018 03:48:14 +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 F315A5DD6B; Mon, 10 Sep 2018 03:48:12 +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 B0F7D181A12F; Mon, 10 Sep 2018 03:48:07 +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 w8A3m6M4021319 for ; Sun, 9 Sep 2018 23:48:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 157022B58E; Mon, 10 Sep 2018 03:48:06 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0C7F52B594 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 326D781DEB 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--.502S4; Mon, 10 Sep 2018 11:48:00 +0800 (CST) From: Shi Lei To: libvir-list@redhat.com Date: Mon, 10 Sep 2018 11:47:51 +0800 Message-Id: <20180910034755.31246-3-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--.502S4 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjTRAEfoUUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbidxC9T1n5eGHo9gAAsy 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.25]); Mon, 10 Sep 2018 03:48:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 10 Sep 2018 03:48:02 +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.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/6] util: file: 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.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 10 Sep 2018 03:48:14 +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/util/virfile.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 01ebdb6..e63fada 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1969,29 +1969,22 @@ int virFileIsCDROM(const char *path) { struct stat st; - int fd; - int ret =3D -1; + VIR_AUTOCLOSE(fd); =20 if ((fd =3D open(path, O_RDONLY | O_NONBLOCK)) < 0) - goto cleanup; + return -1; =20 if (fstat(fd, &st) < 0) - goto cleanup; + return -1; =20 - if (!S_ISBLK(st.st_mode)) { - ret =3D 0; - goto cleanup; - } + if (!S_ISBLK(st.st_mode)) + return 0; =20 /* Attempt to detect via a CDROM specific ioctl */ if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) >=3D 0) - ret =3D 1; - else - ret =3D 0; + return 1; =20 - cleanup: - VIR_FORCE_CLOSE(fd); - return ret; + return 0; } =20 #else --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list