From nobody Sun Feb 8 12:42:51 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=1594893639; cv=none; d=zohomail.com; s=zohoarc; b=c9GpnLtQGZlDBywA9YF2Bkg9BL4A9T30rI+6RCJz9AamN/tk96lRC8UxF8mOaoLR+N0cXjBRykwzeXWe/S02LW1/BtJSq9wRRXgQpmwAavDYSK1sxvM3Ve+gc3cG6L180x9mCo/VQW+wKAdYosrQORNaDJfBM00cgbk3MJAfhjI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594893639; 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=X1MifAO7+Kwzqf1rrYM99tSqQavqkPgxxGz2/NvxiLU=; b=MJRq9bVAWoKXXIeI0mihGw+KBOxHaXQ1NGa0VKZm32ysbaVv7hpcnG9CjUBROuqrvMcdqucL+WjLtxuNoUJ/bF3UQ6NGSGBelN9GpaOR2Ukd+c+4he1sKgdXI6L8t5uIRVHstw6fLVjVrdLm2qU/sPNzHEPa0+taivyOJAlJpn0= 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-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1594893639983758.0405141179812; Thu, 16 Jul 2020 03:00:39 -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-438-zlaimd3hO-GB2q4EQ7VWHA-1; Thu, 16 Jul 2020 06:00:36 -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 331C58015F4; Thu, 16 Jul 2020 10:00: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 0EE9674F64; Thu, 16 Jul 2020 10:00: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 CB7B41800FEE; Thu, 16 Jul 2020 10:00:30 +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 06GA0Srs015248 for ; Thu, 16 Jul 2020 06:00:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0D4672B6DC; Thu, 16 Jul 2020 10:00:28 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.194.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B3452DE72 for ; Thu, 16 Jul 2020 10:00:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594893638; 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=X1MifAO7+Kwzqf1rrYM99tSqQavqkPgxxGz2/NvxiLU=; b=HU0nX40g98GGyxt1nXDBwJdkdbcBV3ilf0IghPkQInyILN31zSUquTl+UuxqjCU7Lec1I8 6obplMQ6ATEn9OEoCiWWTVVAhTmr1Yav07O+lZgq158Vw0PZ5oYY6F3ZCRO4/Giujw4p2r Lks9sjtXrywhm8HkR7HrzRb9m0pDwQs= X-MC-Unique: zlaimd3hO-GB2q4EQ7VWHA-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 008/351] meson: src/util/virfile: rewrite virFileActivateDirOverrideForProg Date: Thu, 16 Jul 2020 11:54:04 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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 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" With meson we no longer have .libs directory with the actual binary so we have to take a different approach to detect if running from build directory. This is not as robust as for autotools because if you select --prefix in the build directory it will incorrectly enable the override as well but nobody should do that. We have to modify some of the tests to not add current build path into PATH variable and use the full path for virsh instead. Otherwise it would be impossible to figure out that we are running virsh from build directory. Signed-off-by: Pavel Hrdina --- src/util/virfile.c | 34 ++++++++++++++++++------- tests/virsh-optparse | 58 +++++++++++++++++++------------------------ tests/virsh-schedinfo | 12 +++------ 3 files changed, 54 insertions(+), 50 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 213acdbcaa2..4542a38278e 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1781,21 +1781,37 @@ virFileFindResource(const char *filename, * virFileActivateDirOverrideForProg: * @argv0: argv[0] of the calling program * - * Look at @argv0 and try to detect if running from - * a build directory, by looking for a 'lt-' prefix - * on the binary name, or '/.libs/' in the path + * Combine $PWD and @argv0, canonicalize it and check if abs_top_builddir + * matches as prefix in the path. */ void virFileActivateDirOverrideForProg(const char *argv0) { - char *file =3D strrchr(argv0, '/'); - if (!file || file[1] =3D=3D '\0') + const char *pwd =3D g_getenv("PWD"); + g_autofree char *fullPath =3D NULL; + g_autofree char *canonPath =3D NULL; + const char *path =3D NULL; + + if (!pwd) return; - file++; - if (STRPREFIX(file, "lt-") || - strstr(argv0, "/.libs/")) { + + if (argv0[0] !=3D '/') { + fullPath =3D g_strdup_printf("%s/%s", pwd, argv0); + canonPath =3D virFileCanonicalizePath(fullPath); + + if (!canonPath) { + VIR_DEBUG("Failed to get canonicalized path errno=3D%d", errno= ); + return; + } + + path =3D canonPath; + } else { + path =3D argv0; + } + + if (STRPREFIX(path, abs_top_builddir)) { useDirOverride =3D true; - VIR_DEBUG("Activating build dir override for %s", argv0); + VIR_DEBUG("Activating build dir override for %s", path); } } =20 diff --git a/tests/virsh-optparse b/tests/virsh-optparse index d9c8f3c731b..fed71a8509e 100755 --- a/tests/virsh-optparse +++ b/tests/virsh-optparse @@ -21,17 +21,11 @@ =20 test_expensive =20 -# If $abs_top_builddir/tools is not early in $PATH, put it there, -# so that we can safely invoke "virsh" simply with its name. -case $PATH in - $abs_top_builddir/tools/src:$abs_top_builddir/tools:*) ;; - $abs_top_builddir/tools:*) ;; - *) PATH=3D$abs_top_builddir/tools:$PATH; export PATH ;; -esac +VIRSH=3D$abs_top_builddir/tools/virsh =20 if test "$VERBOSE" =3D yes; then set -x - virsh --version + $VIRSH --version fi =20 cat <<\EOF > exp-out || framework_failure @@ -63,7 +57,7 @@ for args in \ '--count 2 test' \ '--count=3D2 test' \ ; do - virsh -k0 -d0 -c $test_url setvcpus $args >out 2>>err || fail=3D1 + $VIRSH -k0 -d0 -c $test_url setvcpus $args >out 2>>err || fail=3D1 LC_ALL=3DC sort out | compare exp-out - || fail=3D1 done =20 @@ -81,7 +75,7 @@ cat <<\EOF > exp-out || framework_failure =20 EOF -virsh -q -c $test_url snapshot-create-as --print-xml test \ +$VIRSH -q -c $test_url snapshot-create-as --print-xml test \ --diskspec 'vda,file=3Da&b,,c,snapshot=3Dexternal' --description '1<2' \ --diskspec vdb --memspec file=3Dd,,e >out 2>>err || fail=3D1 compare exp-out out || fail=3D1 @@ -96,7 +90,7 @@ cat <<\EOF > exp-out || framework_failure =20 EOF -virsh -q -c $test_url snapshot-create-as --print-xml test name vda vdb \ +$VIRSH -q -c $test_url snapshot-create-as --print-xml test name vda vdb \ >out 2>>err || fail=3D1 compare exp-out out || fail=3D1 =20 @@ -120,7 +114,7 @@ for args in \ '--description desc --name name --domain test vda vdb' \ '--description desc --diskspec vda --name name --domain test vdb' \ ; do - virsh -q -c $test_url snapshot-create-as --print-xml $args \ + $VIRSH -q -c $test_url snapshot-create-as --print-xml $args \ >out 2>>err || fail=3D1 compare exp-out out || fail=3D1 done @@ -131,7 +125,7 @@ test -s err && fail=3D1 cat <<\EOF > exp-err || framework_failure error: this function is not supported by the connection driver: virDomainQ= emuMonitorCommand EOF -virsh -q -c $test_url qemu-monitor-command test a >out 2>err && fail=3D1 +$VIRSH -q -c $test_url qemu-monitor-command test a >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 @@ -141,7 +135,7 @@ compare exp-err err || fail=3D1 cat <<\EOF > exp-err || framework_failure error: Numeric value 'abc' for option is malformed or out of range EOF -virsh -q -c $test_url cpu-stats test --start abc >out 2>err && fail=3D1 +$VIRSH -q -c $test_url cpu-stats test --start abc >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 @@ -149,7 +143,7 @@ compare exp-err err || fail=3D1 cat <<\EOF > exp-err || framework_failure error: Numeric value '42WB' for option is malformed or out of range EOF -virsh -q -c $test_url cpu-stats test --start 42WB >out 2>err && fail=3D1 +$VIRSH -q -c $test_url cpu-stats test --start 42WB >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 @@ -158,7 +152,7 @@ compare exp-err err || fail=3D1 cat <<\EOF > exp-err || framework_failure error: Numeric value '42MB' for option is malformed or out of range EOF -virsh -q -c $test_url cpu-stats test --start 42MB >out 2>err && fail=3D1 +$VIRSH -q -c $test_url cpu-stats test --start 42MB >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 @@ -166,7 +160,7 @@ compare exp-err err || fail=3D1 cat <<\EOF > exp-err || framework_failure error: Numeric value '2147483648' for option is malformed or out o= f range EOF -virsh -q -c $test_url cpu-stats test --start 2147483648 >out 2>err && fail= =3D1 +$VIRSH -q -c $test_url cpu-stats test --start 2147483648 >out 2>err && fai= l=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 @@ -175,7 +169,7 @@ compare exp-err err || fail=3D1 cat <<\EOF > exp-err || framework_failure error: Invalid value for start CPU EOF -virsh -q -c $test_url cpu-stats test --start -1 >out 2>err && fail=3D1 +$VIRSH -q -c $test_url cpu-stats test --start -1 >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 @@ -185,7 +179,7 @@ compare exp-err err || fail=3D1 cat <<\EOF > exp-err || framework_failure error: Scaled numeric value 'abc' for option is malformed or out of= range EOF -virsh -q -c $test_url setmaxmem test abc >out 2>err && fail=3D1 +$VIRSH -q -c $test_url setmaxmem test abc >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 @@ -194,18 +188,18 @@ cat <<\EOF > exp-err || framework_failure error: Scaled numeric value '42WB' for option is malformed or out o= f range error: invalid argument: unknown suffix 'WB' EOF -virsh -q -c $test_url setmaxmem test 42WB >out 2>err && fail=3D1 +$VIRSH -q -c $test_url setmaxmem test 42WB >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 # Numeric value with valid suffix -virsh -q -c $test_url setmaxmem test 42MB --config >out 2>err || fail=3D1 +$VIRSH -q -c $test_url setmaxmem test 42MB --config >out 2>err || fail=3D1 test -s out && fail=3D1 test -s err && fail=3D1 =20 # Numeric value bigger than INT_MAX. No failure here because # scaled numeric values are unsigned long long -virsh -q -c $test_url setmaxmem test 2147483648 --config >out 2>err || fai= l=3D1 +$VIRSH -q -c $test_url setmaxmem test 2147483648 --config >out 2>err || fa= il=3D1 test -s out && fail=3D1 test -s err && fail=3D1 =20 @@ -213,7 +207,7 @@ test -s err && fail=3D1 cat <<\EOF > exp-err || framework_failure error: Scaled numeric value '-1' for option is malformed or out of = range EOF -virsh -q -c $test_url setmaxmem test -1 >out 2>err && fail=3D1 +$VIRSH -q -c $test_url setmaxmem test -1 >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 @@ -223,12 +217,12 @@ cat <<\EOF > exp-err || framework_failure error: Unable to change MaxMemorySize error: memory in virDomainSetMaxMemory must not be zero EOF -virsh -q -c $test_url setmaxmem test 0 >out 2>err && fail=3D1 +$VIRSH -q -c $test_url setmaxmem test 0 >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 # Numeric value -virsh -q -c $test_url setmaxmem test 42 --config >out 2>err || fail=3D1 +$VIRSH -q -c $test_url setmaxmem test 42 --config >out 2>err || fail=3D1 test -s out && fail=3D1 test -s err && fail=3D1 =20 @@ -238,7 +232,7 @@ test -s err && fail=3D1 cat <<\EOF > exp-err || framework_failure error: Numeric value 'abc' for option is malformed or out of ran= ge EOF -virsh -q -c $test_url event --all --timeout abc >out 2>err && fail=3D1 +$VIRSH -q -c $test_url event --all --timeout abc >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 @@ -247,7 +241,7 @@ compare exp-err err || fail=3D1 cat <<\EOF > exp-err || framework_failure error: Numeric value '2147484' for option is malformed or out of= range EOF -virsh -q -c $test_url event --all --timeout 2147484 >out 2>err && fail=3D1 +$VIRSH -q -c $test_url event --all --timeout 2147484 >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 @@ -255,7 +249,7 @@ compare exp-err err || fail=3D1 cat <<\EOF > exp-err || framework_failure error: Numeric value '42WB' for option is malformed or out of ra= nge EOF -virsh -q -c $test_url event --all --timeout 42WB >out 2>err && fail=3D1 +$VIRSH -q -c $test_url event --all --timeout 42WB >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 @@ -264,7 +258,7 @@ compare exp-err err || fail=3D1 cat <<\EOF > exp-err || framework_failure error: Numeric value '42MB' for option is malformed or out of ra= nge EOF -virsh -q -c $test_url event --all --timeout 42MB >out 2>err && fail=3D1 +$VIRSH -q -c $test_url event --all --timeout 42MB >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 @@ -272,7 +266,7 @@ compare exp-err err || fail=3D1 cat <<\EOF > exp-err || framework_failure error: Numeric value '-1' for option is malformed or out of range EOF -virsh -q -c $test_url event --all --timeout -1 >out 2>err && fail=3D1 +$VIRSH -q -c $test_url event --all --timeout -1 >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 @@ -281,7 +275,7 @@ compare exp-err err || fail=3D1 cat <<\EOF > exp-err || framework_failure error: Numeric value '0' for option is malformed or out of range EOF -virsh -q -c $test_url event --all --timeout 0 >out 2>err && fail=3D1 +$VIRSH -q -c $test_url event --all --timeout 0 >out 2>err && fail=3D1 test -s out && fail=3D1 compare exp-err err || fail=3D1 =20 @@ -291,7 +285,7 @@ cat <<\EOF > exp-out || framework_failure event loop timed out events received: 0 EOF -virsh -q -c $test_url event --all --timeout 1 >out 2>err && fail=3D1 +$VIRSH -q -c $test_url event --all --timeout 1 >out 2>err && fail=3D1 test -s err && fail=3D1 compare exp-out out || fail=3D1 =20 diff --git a/tests/virsh-schedinfo b/tests/virsh-schedinfo index d6d9ac2d59e..e4e2509f762 100755 --- a/tests/virsh-schedinfo +++ b/tests/virsh-schedinfo @@ -19,17 +19,11 @@ =20 . "$(dirname $0)/test-lib.sh" =20 -# If $abs_top_builddir/tools is not early in $PATH, put it there, -# so that we can safely invoke "virsh" simply with its name. -case $PATH in - $abs_top_builddir/tools/src:$abs_top_builddir/tools:*) ;; - $abs_top_builddir/tools:*) ;; - *) PATH=3D$abs_top_builddir/tools:$PATH; export PATH ;; -esac +VIRSH=3D$abs_top_builddir/tools/virsh =20 if test "$VERBOSE" =3D yes; then set -x - virsh --version + $VIRSH --version fi =20 printf 'Scheduler : fair\n\n' > exp-out || framework_failure @@ -39,7 +33,7 @@ fail=3D0 =20 test_url=3Dtest:///default =20 -virsh -c $test_url schedinfo 1 --set j=3Dk >out 2>err && fail=3D1 +$VIRSH -c $test_url schedinfo 1 --set j=3Dk >out 2>err && fail=3D1 compare exp-out out || fail=3D1 compare exp-err err || fail=3D1 =20 --=20 2.26.2