From nobody Tue Sep 9 03:20:43 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1749732636; cv=none; d=zohomail.com; s=zohoarc; b=jLGFYiwmxXd1191NoEgX0MkX6mxXE76RejS1hAy9p1bUw+YbaGpqRqIoOmLEXrxzhhVOIugaJgjuy2+ZBkl2+dkvy+VkaVckK7Os8Hte1BZBHG5WgAYUorlgz5i3P1nRyQbZWtttN2sX2IYlNUWRUxE+YOUPq6TCxza5jc6boYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749732636; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=8Ev7hjddgGTE4BjIUL3aZ+KwwY/ou+4vAkOH4Gd1wsU=; b=iWiFqXZ5A7vuLk6X6PRemJSlqcWL+X5tLvupTX9EXmAbVmP/eq6aYDgbz3IugApUSSDAYbeZvoHRcWSXP/vaPvraPFs2qygbp1fPEIpcHOQLhFIq5QJrXA+SElRlDDR9nxd4uieaxY2CNG7hqj4qZMpTl6/+UfOhEpUZwCQ4PYY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1749732636959225.91883773382813; Thu, 12 Jun 2025 05:50:36 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C12B112C7; Thu, 12 Jun 2025 08:50:35 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 4039912F0; Thu, 12 Jun 2025 08:49:04 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7E1BBD46; Thu, 12 Jun 2025 08:48:57 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 08CC39CE for ; Thu, 12 Jun 2025 08:48:57 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-150-o5sSNjV-P4ubdOXTJubTBA-1; Thu, 12 Jun 2025 08:48:55 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 99F1918002EC for ; Thu, 12 Jun 2025 12:48:54 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E5341195609D for ; Thu, 12 Jun 2025 12:48:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749732536; h=from:from: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; bh=Yl9ZpEdcupEVQfj/helVcM1m21dykcg7ijm6R3M+fGE=; b=E5ZtkHjvNH+ytnbNyqVF67P7jBLt2tom7DzsVugrveSsrUjR11Nw1AxlERk4jre61KwavY VdswMQA/VcKU7vGexdbqmPLsqWJSPJq/yil0JCA3iDnZahFeqhebSOetX2rGoFKnw8cTi4 HLB5XwHqN4Xc/PKb5kuoFmsRBj8UvHo= X-MC-Unique: o5sSNjV-P4ubdOXTJubTBA-1 X-Mimecast-MFC-AGG-ID: o5sSNjV-P4ubdOXTJubTBA_1749732534 To: devel@lists.libvirt.org Subject: [PATCH 03/15] virpcimock: Automatically invent fakerootdir, if not provided Date: Thu, 12 Jun 2025 14:48:35 +0200 Message-ID: <486337c9110893062bb2f3aae862133e68a292ea.1749732372.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: -M1_HL_-l1kIx9N0Bw_2ROhXGm4XMxYUvMNWesPQc-g_1749732534 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: OMBWJEQNUXSYKIEKWWVG5DEXIUWZ6GSF X-Message-ID-Hash: OMBWJEQNUXSYKIEKWWVG5DEXIUWZ6GSF X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749732637278116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik Currently, all users of virpcimock do set LIBVIRT_FAKE_ROOT_DIR envvar. But soon, virt-aa-helper will be run with it and basically right at the beginning of its main() it clears whole environment. So even if the envvar is provided the mock won't see that. Anyway, the solution is to just create a tempdir and then 'rm -rf' it in the desctructor. Signed-off-by: Michal Privoznik --- tests/virpcimock.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 5b923c63ce..34128d5516 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -44,6 +44,7 @@ static DIR * (*real_opendir)(const char *name); static char *(*real_virFileCanonicalizePath)(const char *path); =20 static char *fakerootdir; +static bool fakerootClean; =20 /* To add a new mocked prefix in virpcimock: * - add the prefix here as a define to make it easier to track what we @@ -976,8 +977,16 @@ init_env(void) .vpd_len =3D G_N_ELEMENTS(fullVPDExampleData), }; =20 - if (!(fakerootdir =3D getenv("LIBVIRT_FAKE_ROOT_DIR"))) - ABORT("Missing LIBVIRT_FAKE_ROOT_DIR env variable\n"); + if (!(fakerootdir =3D getenv("LIBVIRT_FAKE_ROOT_DIR"))) { + GError *err =3D NULL; + + fakerootdir =3D g_dir_make_tmp(NULL, &err); + if (err !=3D NULL) { + ABORT("Unable to create a temporary dir: %s\n", err->message); + } + + fakerootClean =3D true; + } =20 tmp =3D g_strdup_printf("%s%s", fakerootdir, SYSFS_PCI_PREFIX); =20 @@ -1046,6 +1055,18 @@ init_env(void) } =20 =20 +static void __attribute__((destructor)) +deinit_env(void) +{ + if (!fakerootClean) + return; + + virFileDeleteTree(fakerootdir); + g_clear_pointer(&fakerootdir, g_free); + fakerootClean =3D false; +} + + /* * * Mocked functions --=20 2.49.0