From nobody Mon Feb 9 10:47:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1603849005; cv=none; d=zohomail.com; s=zohoarc; b=JUchsj3Av7cIBGLGyabZrUbARJnl9QeHARVyScw78UBw3iqiYtxM6/3NDhdABEkYOwA9A5bajvZ7r1LYuGHXe03GkxlpUDgLetbz4EhFmv7ih4+eGdBMO2Tq/llAkcOeZZKOe7JkW4FISqKfRXwGxc87bBLK/YiovKZsD51c5E4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603849005; 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=1dspbdOCeIXSYo4u44driwE+2NSKYgM4fTeXnPxVQrU=; b=FnIEMa8Lvj8iBF/ZrrOH5D2dSjPi/f1jTiwzlXbKHRi98rx2b0kX4MNJsQiROt5es1UptULuENjvd4su2QJH3TUqhymliraPlrOp0O1qFKdURN/K68r54+HbIqE1YkiFR36UDTvzf9skIoJ2pABS6eIgNyAVq2PGZKiTfnPrLAY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1603849005894481.1294080599512; Tue, 27 Oct 2020 18:36:45 -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-555--Dr21_RFO6m91_HkV6q5wA-1; Tue, 27 Oct 2020 21:36:42 -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 7FEFF1084D76; Wed, 28 Oct 2020 01:36:31 +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 5BB2119D61; Wed, 28 Oct 2020 01:36:31 +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 22100181A88C; Wed, 28 Oct 2020 01:36:31 +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 09S1a8mt028258 for ; Tue, 27 Oct 2020 21:36:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id C8F585C6DD; Wed, 28 Oct 2020 01:36:08 +0000 (UTC) Received: from vhost2.laine.org (ovpn-113-144.phx2.redhat.com [10.3.113.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 830F55C22A for ; Wed, 28 Oct 2020 01:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603849004; 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=1dspbdOCeIXSYo4u44driwE+2NSKYgM4fTeXnPxVQrU=; b=aoSEoP+fHo+xAmP3VIVKVKfx9pOx9aPvmqzegr2liEuG1v6DuWHM2suo25Lg2ruFCfdluf Vy6AVMqgtqEOh8IuDMvLFD6sbAWwwUvunzsVWfoovYnkIRpr3/GSBCQHT/zT17mG+FIOKI D+bYv/KGUe04yIvkDvEMCjq1ARHhKlo= X-MC-Unique: -Dr21_RFO6m91_HkV6q5wA-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 06/12] util: change virDirClose to take a DIR* instead of DIR**. Date: Tue, 27 Oct 2020 21:35:52 -0400 Message-Id: <20201028013558.424925-7-laine@redhat.com> In-Reply-To: <20201028013558.424925-1-laine@redhat.com> References: <20201028013558.424925-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.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.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" In order to make a usable g_autoptr(DIR), we need to have a close function that is a NOP when the pointer is NULL, but takes a simple DIR*. But virDirClose() (candidate to be the g_autoptr cleanup function) currently takes a DIR**, not DIR*. It does this so that it can clear the pointer, thus making it safe to call virDirClose on the same DIR multiple times. In the past the clearing of the DIR* was essential in a few places, but those few places have now been changed, so we can modify virDirClose() to take a DIR*, and remove the side effect of clearing the DIR*. This will make it directly usable as the g_autoptr cleanup, and will mean that this: { DIR *dirp =3D NULL; blah blah ... VIR_DIR_CLOSE(dirp) } is functionally identical to { g_autoptr(DIR) dirp =3D NULL; blah blah ... } which will make conversion to using g_autoptr mechanical and simple to revi= ew. (Note that virDirClose() will still check for NULL before attempting to close, so that it can always be safely called, as long as the DIR* was initialized to NULL (another prerequisite of becoming a g_autoptr cleanup function) Signed-off-by: Laine Stump --- src/util/virfile.c | 7 +++---- src/util/virfile.h | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 970d4bd234..442d2fab96 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -2927,13 +2927,12 @@ int virDirRead(DIR *dirp, struct dirent **ent, cons= t char *name) return !!*ent; } =20 -void virDirClose(DIR **dirp) +void virDirClose(DIR *dirp) { - if (!*dirp) + if (!dirp) return; =20 - closedir(*dirp); /* exempt from syntax-check */ - *dirp =3D NULL; + closedir(dirp); /* exempt from syntax-check */ } =20 =20 diff --git a/src/util/virfile.h b/src/util/virfile.h index 09488398c5..6fde4f88ca 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -269,9 +269,9 @@ int virDirOpenQuiet(DIR **dirp, const char *dirname) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; int virDirRead(DIR *dirp, struct dirent **ent, const char *dirname) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; -void virDirClose(DIR **dirp) +void virDirClose(DIR *dirp) ATTRIBUTE_NONNULL(1); -#define VIR_DIR_CLOSE(dir) virDirClose(&(dir)) +#define VIR_DIR_CLOSE(dir) virDirClose(dir) =20 int virFileMakePath(const char *path) G_GNUC_WARN_UNUSED_RESULT; int virFileMakePathWithMode(const char *path, --=20 2.26.2