From nobody Sun Feb 8 22:08:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1594151239; cv=none; d=zohomail.com; s=zohoarc; b=j6a954A/x7I1ZqR7UYJs3AcNWG3WDGruV25HoXtBw7ROAR3szNW11RiDcrP3m+0MLgEYkgEHuNcOuLU7Hz2//jCL+356muXRB62TBrJJQe26Jb0gdCMxM0kcW7WYKXAMnjhIYa/rUAF3dM5QNJ78LZYTP/3WJ6vMcOr1gD8RGZw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594151239; 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=sqkWprPFk0ASMEDNskeK2fAPFN2BgF0lq+NB0oaM+k4=; b=VZMbv2RyQjjWoncCHgn3geTVXJu3sC76lXlSMfsSpodcDR/gVbsUtj+/vi+cA0JjIu+h3b9t+T3W8fTMSZbtsWaYDPt0viFQi9aXSUTs1aMTmXEBMEQMUJ2lkLLVkybkvIRhkQYSzOhs/RRyDF9CU4sCXFBuh/3pEneGjqzSyzc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.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 1594151239055808.2267838592182; Tue, 7 Jul 2020 12:47:19 -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-410-7yC1I2jvN6ee-N3wjKUnog-1; Tue, 07 Jul 2020 15:47:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CC6EB80572D; Tue, 7 Jul 2020 19:47:09 +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 58251797F6; Tue, 7 Jul 2020 19:47:09 +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 1EF8B93F77; Tue, 7 Jul 2020 19:47:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067JkiQI031457 for ; Tue, 7 Jul 2020 15:46:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id B85C1797EF; Tue, 7 Jul 2020 19:46:44 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3679F797F2 for ; Tue, 7 Jul 2020 19:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594151237; 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=sqkWprPFk0ASMEDNskeK2fAPFN2BgF0lq+NB0oaM+k4=; b=dBdcI4zK0mde8BWGq0w6xpcFcfSxCajiJr/sBdYMDthwn7Lesf7oI3PtCnlRR+rFyQRfgx j/7JMaZJGjsOOGDqjt5InfHMpuMET9LMD6CqLsFYDsuS93oq2Ek6sKEJMP9sN637mqmqEo QRMFLfnW/IBKE6PqOhV2z/8N5JQMnFE= X-MC-Unique: 7yC1I2jvN6ee-N3wjKUnog-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 05/17] virfdstream: Use VIR_AUTOCLOSE() Date: Tue, 7 Jul 2020 21:46:23 +0200 Message-Id: <8b570cd2cb917c1b6e0e880e8a43fb747e8ade29.1594150891.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.79 on 10.5.11.13 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" Again, instead of closing FDs explicitly, we can automatically close them when they go out of their respective scopes. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/util/virfdstream.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index c85dee05c3..bac1c95c0a 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -571,9 +571,9 @@ virFDStreamThread(void *opaque) virStreamPtr st =3D data->st; size_t length =3D data->length; bool sparse =3D data->sparse; - int fdin =3D data->fdin; + VIR_AUTOCLOSE fdin =3D data->fdin; char *fdinname =3D data->fdinname; - int fdout =3D data->fdout; + VIR_AUTOCLOSE fdout =3D data->fdout; char *fdoutname =3D data->fdoutname; virFDStreamDataPtr fdst =3D st->privateData; bool doRead =3D fdst->threadDoRead; @@ -633,8 +633,6 @@ virFDStreamThread(void *opaque) virObjectUnref(fdst); if (virFDStreamDataDisposed) st->privateData =3D NULL; - VIR_FORCE_CLOSE(fdin); - VIR_FORCE_CLOSE(fdout); virFDStreamThreadDataFree(data); return; =20 @@ -1160,9 +1158,10 @@ int virFDStreamConnectUNIX(virStreamPtr st, { struct sockaddr_un sa; virTimeBackOffVar timeout; + VIR_AUTOCLOSE fd =3D -1; int ret; =20 - int fd =3D socket(AF_UNIX, SOCK_STREAM, 0); + fd =3D socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) { virReportSystemError(errno, "%s", _("Unable to open UNIX socket")); goto error; @@ -1197,10 +1196,11 @@ int virFDStreamConnectUNIX(virStreamPtr st, =20 if (virFDStreamOpenInternal(st, fd, NULL, 0) < 0) goto error; + + fd =3D -1; return 0; =20 error: - VIR_FORCE_CLOSE(fd); return -1; } =20 --=20 2.26.2