From nobody Sun Feb 8 12:42:43 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=1618600424; cv=none; d=zohomail.com; s=zohoarc; b=nNOpTiB6D0YOpC6NzZ0uIltZ+vJdttsdJ1eSI0WP4C9TLuYOZBJWM3tFJtINV9Ox4fuzXREyGSlgA3yVOh1bwUHAGntA20MA4N/8YUVyDiUQMMIsM9qoyRpBxHRwViO/MDqGskqYlLSDEvhk3OeHmjo3Ab9qiIDG8aYP+9eX0J4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618600424; 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=vkpZXaNRdnCvB3tKj5FwMAUwTYKQ9Dmowdn0GlZF0Lo=; b=PulBYp7LLDmcdp56GcMlWBqv6weWn9dmb9XtRGE5seCjAN2yT9HWA7ZPFZMwSd98V3QagUGNWpbYQbyVj9uYMWUmp33tJklTMKvPOQ6XQVwGALodb05F//bdw8jq5yEyBwxvkUUGvSlZC4TWpakm51/ls2OJV7OWqd93ThRnJcM= 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) header.from= 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 1618600423979506.616606224807; Fri, 16 Apr 2021 12:13:43 -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-65-1U05YFAXPeuYBI5EtNsi2w-1; Fri, 16 Apr 2021 15:13:40 -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 13838106BB2A; Fri, 16 Apr 2021 19:13:33 +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 E7F2F5F7D0; Fri, 16 Apr 2021 19:13:32 +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 A7E0D55355; Fri, 16 Apr 2021 19:13:32 +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 13GJD4jC028335 for ; Fri, 16 Apr 2021 15:13:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id DFD755D749; Fri, 16 Apr 2021 19:13:04 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.195.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5EF545D6D3 for ; Fri, 16 Apr 2021 19:13:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618600422; 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=vkpZXaNRdnCvB3tKj5FwMAUwTYKQ9Dmowdn0GlZF0Lo=; b=PAXsVuXTxC3HweIz+AUxaJvF/0ovbx/8QuNYmdbM6lM+PwZsdJZzL/il1LrBSix5vakZlq cUcBe+8Ifrf/kg7UKuUMP9yO2AuG75HifBE2N0uRN+xFqaCILy7LEZIfz92ap3TVCgqqN4 cJDWqYAMVEAxgq1KrMESrmRHkczy5Ao= X-MC-Unique: 1U05YFAXPeuYBI5EtNsi2w-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 14/17] virfile: introduce virFindFileInPathFull() Date: Fri, 16 Apr 2021 21:12:43 +0200 Message-Id: <08b515912afd75a1ee28bb77e834a8f4fa457c52.1618600267.git.phrdina@redhat.com> 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.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" Extend virFindFileInPath to search in custom extra paths as well. Some binaries that libvirt needs are not usually in $PATH so we need to have a way to look for these as well. Signed-off-by: Pavel Hrdina --- src/libvirt_private.syms | 2 +- src/util/virfile.c | 16 ++++++++++++++-- src/util/virfile.h | 5 ++++- tests/domaincapsmock.c | 3 ++- tests/virfirewallmock.c | 3 ++- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d507a858ac..c765289085 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2253,7 +2253,7 @@ virFileWrapperFdClose; virFileWrapperFdFree; virFileWrapperFdNew; virFileWriteStr; -virFindFileInPath; +virFindFileInPathFull; =20 =20 # util/virfilecache.h diff --git a/src/util/virfile.c b/src/util/virfile.c index 03a7725dd3..7922fda2e5 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1654,13 +1654,15 @@ virFileIsLink(const char *linkpath) } =20 /* - * Finds a requested executable file in the PATH env. e.g.: + * Finds a requested executable file in the paths provided by @extra_paths + * argument or in PATH env. e.g.: * "qemu-img" will return "/usr/bin/qemu-img" * * You must free the result */ char * -virFindFileInPath(const char *file) +virFindFileInPathFull(const char *file, + const GStrv extra_paths) { const char *origpath =3D NULL; g_auto(GStrv) paths =3D NULL; @@ -1692,6 +1694,16 @@ virFindFileInPath(const char *file) return abspath; } =20 + /* First search in paths provided by caller. + */ + if (extra_paths) { + for (pathiter =3D extra_paths; *pathiter; pathiter++) { + g_autofree char *fullpath =3D g_strdup_printf("%s/%s", *pathit= er, file); + if (virFileIsExecutable(fullpath)) + return g_steal_pointer(&fullpath); + } + } + /* copy PATH env so we can tweak it */ origpath =3D getenv("PATH"); if (!origpath) diff --git a/src/util/virfile.h b/src/util/virfile.h index b9f7b1766f..eee27c2efc 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -184,9 +184,12 @@ int virFileResolveAllLinks(const char *linkpath, int virFileIsLink(const char *linkpath) ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT; =20 -char *virFindFileInPath(const char *file) +char *virFindFileInPathFull(const char *file, + const GStrv extra_paths) G_GNUC_NO_INLINE; =20 +#define virFindFileInPath(file) virFindFileInPathFull(file, NULL) + char *virFileFindResource(const char *filename, const char *builddir, const char *installdir) diff --git a/tests/domaincapsmock.c b/tests/domaincapsmock.c index 73690f0b9e..4bef2b72d0 100644 --- a/tests/domaincapsmock.c +++ b/tests/domaincapsmock.c @@ -43,7 +43,8 @@ virHostCPUGetMicrocodeVersion(virArch hostArch G_GNUC_UNU= SED) } =20 char * -virFindFileInPath(const char *file) +virFindFileInPathFull(const char *file, + const GStrv extra_args G_GNUC_UNUSED) { if (g_str_has_prefix(file, "qemu-system") || g_str_equal(file, "qemu-kvm")) { diff --git a/tests/virfirewallmock.c b/tests/virfirewallmock.c index 6b096701c9..a047e56bd9 100644 --- a/tests/virfirewallmock.c +++ b/tests/virfirewallmock.c @@ -20,7 +20,8 @@ #include "virfile.h" =20 char * -virFindFileInPath(const char *file) +virFindFileInPathFull(const char *file, + const GStrv extra_args G_GNUC_UNUSED) { if (file && (g_strrstr(file, "ebtables") || --=20 2.30.2