From nobody Sun Feb 8 03:11:17 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=1628177766; cv=none; d=zohomail.com; s=zohoarc; b=lWSmToXrT52qIQosxC5rDT1cTu0W8NsdWNGbB8AQGHj+uH8Fm1W6TPcCf7p2kRxq2jVL/N4k6dvxrgJaeTIMMQsGYQ2pOorn1m4j2YHvzbKCgIOAMuIIFKw1wLqL8hQCx6+WYDhVDDKUMM0k7zdX/CqkavpL/JzULuDKR0mz+4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628177766; 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=F6JyD785JWbHwacNRNK7ALH7k4m38W3t3uWwPbnkDNM=; b=hdDlgELgeIKkP0tnnGqE0IYZ6fz4BqiWGaXfwd9Z19pM509WgGpHuJzcfaiEjlXmTdjkkxUmngAWz+g8y4LAzS8L9QHUUKu3xduidJTNK+UVugAODoA8Jw8JvgEplxx2+3PpM7HXNYUJZj71UMI8mHZGyf1U0FaDG1ikkdgufy0= 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) 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 1628177766729113.31973139740705; Thu, 5 Aug 2021 08:36:06 -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-304-vaD65XmYNeGD8sQECrlHug-1; Thu, 05 Aug 2021 11:35:12 -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 7F377100CA8D; Thu, 5 Aug 2021 15:35:07 +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 534DC27CAA; Thu, 5 Aug 2021 15:35:07 +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 16833181A6E6; Thu, 5 Aug 2021 15:35:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 175FZ0T3027835 for ; Thu, 5 Aug 2021 11:35:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5CBEC669F3; Thu, 5 Aug 2021 15:35:00 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA2D15D6B1 for ; Thu, 5 Aug 2021 15:34:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628177765; 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=F6JyD785JWbHwacNRNK7ALH7k4m38W3t3uWwPbnkDNM=; b=X1uXdIZhaqOu/MA54reCWISGkH85jPYG+UCJMFBPOb0Ai00fY3GpyHyXXvNEQrMOaXiFG6 rTKM9eMyejDUDYznk/+Bdffe+Gmkdb4v5Mn4mazTc/6EjMkXRlyuJDw04hlUyluMkVntVT GtgzF1SX7hZ8zAWPonOp9Knc8GujFJU= X-MC-Unique: vaD65XmYNeGD8sQECrlHug-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 12/13] lxcContainerSetReadOnly: Refactor cleanup handling Date: Thu, 5 Aug 2021 17:34:28 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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) X-ZM-MESSAGEID: 1628177768724100001 Content-Type: text/plain; charset="utf-8" Turn 'mounts' into a proper GStrv after sorting so that automatic cleanup can be used and shuffle around the cleanup steps so that jumps can be avoided in favor of direct return of error code. Signed-off-by: Peter Krempa --- src/lxc/lxc_container.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 1cadfe70e0..d788e77196 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -773,8 +773,7 @@ static int lxcContainerSetReadOnly(void) FILE *procmnt; struct mntent mntent; char mntbuf[1024]; - int ret =3D -1; - char **mounts =3D NULL; + g_auto(GStrv) mounts =3D NULL; size_t nmounts =3D 0; size_t i; @@ -797,13 +796,16 @@ static int lxcContainerSetReadOnly(void) VIR_APPEND_ELEMENT(mounts, nmounts, tmp); } - if (!mounts) { - ret =3D 0; - goto cleanup; - } + endmntent(procmnt); + + if (!mounts) + return 0; + + qsort(mounts, nmounts, sizeof(mounts[0]), virStringSortRevCompare); - qsort(mounts, nmounts, sizeof(mounts[0]), - virStringSortRevCompare); + /* turn 'mounts' into a proper GStrv */ + VIR_EXPAND_N(mounts, nmounts, 1); + nmounts--; for (i =3D 0; i < nmounts; i++) { VIR_DEBUG("Bind readonly %s", mounts[i]); @@ -811,16 +813,11 @@ static int lxcContainerSetReadOnly(void) virReportSystemError(errno, _("Failed to make mount %s readonly"), mounts[i]); - goto cleanup; + return -1; } } - ret =3D 0; - cleanup: - virStringListFreeCount(mounts, nmounts); - endmntent(procmnt); - return ret; - + return 0; } --=20 2.31.1