From nobody Sun Apr 28 10:17:58 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567076090; cv=none; d=zoho.com; s=zohoarc; b=hKU/AwpXmIPjWgCf0sj2EwhHKcDedf3Gw4viQgMfqH34+Tw3pQZNSC5wl0+Se/6cqCDOXjCAmdMoGAqljaFncFuR4dGJ6wsuCilct3IFEDh7RmmNGnqE7x+jpY2N9WZQfIrZOpU9nIDle3u7TmjQ6QOGJs9ORj9iK1fb4mQ3+BY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567076090; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=zr6rVJqA4GfpyGSElkYxgGInJUAWuIJG3sJeNXsNHXM=; b=fefkooukx5wuWXqVhXEwRyCx/mBRrdgp+mq8flPupsuLYRe0EdzWfgJL4zBE5P4txKZujuKkigvR/Ss06JJUaSwWWDoxGgaHxVZO23vFCbwaU842QPU5xwHhOO/pNJGzUv1kGYo9RGuK6UV45xTL7tC71ppFZA/18AYvKHMQgoc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1567076090060566.8296266354165; Thu, 29 Aug 2019 03:54:50 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 262308D5B9E; Thu, 29 Aug 2019 10:54:48 +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 3CC456060D; Thu, 29 Aug 2019 10:54:47 +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 72A5E2551D; Thu, 29 Aug 2019 10:54:45 +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 x7TAshxk004505 for ; Thu, 29 Aug 2019 06:54:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id D6C824523; Thu, 29 Aug 2019 10:54:43 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD3754116; Thu, 29 Aug 2019 10:54:39 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 29 Aug 2019 11:54:37 +0100 Message-Id: <20190829105437.11741-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] util: activate directory override when used from library 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: , Content-Type: text/plain; charset="utf-8" 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Thu, 29 Aug 2019 10:54:48 +0000 (UTC) The Perl bindings for libvirt use the test driver for unit tests. This tries to load the cpu_map/index.xml file, and when run from an uninstalled build will fail. The problem is that virFileActivateDirOverride is called by our various binaries like libvirtd, virsh, but is not called when a 3rd party app uses libvirt.so To deal with this we allow the LIBVIRT_DIR_OVERRIDE=3D1 env variable to be set and make virInitialize look for this. The 'run' script will set it, so now build using this script to run against an uninstalled tree we will correctly resolve files to the source tree. Signed-off-by: Daniel P. Berrang=C3=A9 --- run.in | 3 +++ src/libvirt.c | 2 ++ src/util/virfile.c | 21 +++++++++++++-------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/run.in b/run.in index 9a1c6ea11a..de7af78f67 100644 --- a/run.in +++ b/run.in @@ -60,6 +60,9 @@ else fi export PKG_CONFIG_PATH =20 +LIBVIRT_DIR_OVERRIDE=3D1 +export LIBVIRT_DIR_OVERRIDE + # This is a cheap way to find some use-after-free and uninitialized # read problems when using glibc. random_val=3D"$(awk 'BEGIN{srand(); print 1+int(255*rand())}' < /dev/null)" diff --git a/src/libvirt.c b/src/libvirt.c index 956ccdea30..6b1b4a54c3 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -250,6 +250,8 @@ virGlobalInit(void) virErrorInitialize() < 0) goto error; =20 + virFileActivateDirOverride(NULL); + if (getuid() !=3D geteuid() || getgid() !=3D getegid()) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/util/virfile.c b/src/util/virfile.c index 81a3c096eb..391b6a9e6e 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1776,14 +1776,19 @@ virFileFindResource(const char *filename, void virFileActivateDirOverride(const char *argv0) { - char *file =3D strrchr(argv0, '/'); - if (!file || file[1] =3D=3D '\0') - return; - file++; - if (STRPREFIX(file, "lt-") || - strstr(argv0, "/.libs/")) { - useDirOverride =3D true; - VIR_DEBUG("Activating build dir override for %s", argv0); + if (argv0 =3D=3D NULL) { + if (getenv("LIBVIRT_DIR_OVERRIDE") !=3D NULL) + useDirOverride =3D true; + } else { + char *file =3D strrchr(argv0, '/'); + if (!file || file[1] =3D=3D '\0') + return; + file++; + if (STRPREFIX(file, "lt-") || + strstr(argv0, "/.libs/")) { + useDirOverride =3D true; + VIR_DEBUG("Activating build dir override for %s", argv0); + } } } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list