From nobody Fri Dec 19 04:32:18 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1683309719; cv=none; d=zohomail.com; s=zohoarc; b=YulEHRpyXrsFOMK3zfExf2IEHe7HYSZTaFEEYhYxEqy7ASalIapjhJNnSsJoMhcBF069X95RbeeglTM9N/MHnWuHg+BvVAlZGAhAz7ltMM9wJPHVERj2l2PyVWshL1jiE6/PhAY6lnNW2NRhyt8XoDkb6adHHMtYpYa6WPNFAV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683309719; 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=Bswrv4ixAwaeCliNg/kV2ZfKYlwskNXxHtrCMzK0Y5I=; b=nzTAfhpl432cWpAxCXq+8nt+Y4J4m1AEYc/B7Hkgsme6QWK2aCTe3YLrjOobp4In13ZYY4CXJJIIUyb1XX6ftUTxKjwr3ZUv6CGlHhxk6HhfKtZW4pzp95dIg0evjHvWeWrG30We/3lYZhpI2hChlsgKh8f266XIrX0olzbhXoE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 168330971971059.01670743276952; Fri, 5 May 2023 11:01:59 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-510--CK_4pdpNnOjMj0uP8SL8w-1; Fri, 05 May 2023 14:01:55 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CF7FD100F661; Fri, 5 May 2023 18:01:50 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC67963F3D; Fri, 5 May 2023 18:01:50 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 925891946A62; Fri, 5 May 2023 18:01:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2BBE21946A43 for ; Fri, 5 May 2023 18:01:50 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 034B62026D25; Fri, 5 May 2023 18:01:50 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.45.224.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 862D72026D16 for ; Fri, 5 May 2023 18:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683309718; 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=Bswrv4ixAwaeCliNg/kV2ZfKYlwskNXxHtrCMzK0Y5I=; b=PCLA36h0ssIlp+greIkhrNIjaS+4XQB4uTl8KXNMB7+VNxAeE2LutbDVQaS6jtPDwwBbZc yMaJcjrkd1rq6Hrl6FBFBafg2xLqBKoCDino3vAVJzR7XBBw8mK4GJ3dwPK+6RJBo9YWRL 2aYuOqFjOLyQIYuoAfhYvDCMyzKvhPo= X-MC-Unique: -CK_4pdpNnOjMj0uP8SL8w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 2/5] util: Introduce virFileFindInPathFull() Date: Fri, 5 May 2023 20:01:43 +0200 Message-Id: <20230505180146.551086-3-abologna@redhat.com> In-Reply-To: <20230505180146.551086-1-abologna@redhat.com> References: <20230505180146.551086-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: 1683309721912100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Andrea Bolognani --- src/libvirt_private.syms | 1 + src/util/virfile.c | 33 +++++++++++++++++++++++++++++++++ src/util/virfile.h | 3 +++ 3 files changed, 37 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 62c296bf5f..27b8e111aa 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2358,6 +2358,7 @@ virFileWrapperFdFree; virFileWrapperFdNew; virFileWriteStr; virFindFileInPath; +virFindFileInPathFull; =20 =20 # util/virfilecache.h diff --git a/src/util/virfile.c b/src/util/virfile.c index 8e94d19e45..6b4d4c3522 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1737,6 +1737,25 @@ virFileIsLink(const char *linkpath) */ char * virFindFileInPath(const char *file) +{ + return virFindFileInPathFull(file, NULL); +} + +/* virFindFileInPathFull: + * @file: name of the program + * @extraDirs: NULL-terminated list of additional directories + * + * Like virFindFileInPath(), but in addition to searching $PATH also + * looks into all directories listed in @extraDirs. This is useful to + * locate helpers that are installed outside of $PATH. + * + * The returned path must be freed by the caller. + * + * Returns: absolute path of the program or NULL + */ +char * +virFindFileInPathFull(const char *file, + const char *const *extraDirs) { g_autofree char *path =3D NULL; if (file =3D=3D NULL) @@ -1751,6 +1770,20 @@ virFindFileInPath(const char *file) return g_canonicalize_filename(path, NULL); } =20 + if (extraDirs) { + while (*extraDirs) { + g_autofree char *extraPath =3D NULL; + + extraPath =3D g_strdup_printf("%s/%s", *extraDirs, file); + + if (virFileIsExecutable(extraPath)) { + return g_steal_pointer(&extraPath); + } + + extraDirs++; + } + } + return NULL; } =20 diff --git a/src/util/virfile.h b/src/util/virfile.h index f7a31d9f57..6a14173625 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -189,6 +189,9 @@ int virFileIsLink(const char *linkpath) =20 char *virFindFileInPath(const char *file) G_NO_INLINE; +char *virFindFileInPathFull(const char *file, + const char *const *extraDirs) + G_NO_INLINE; =20 char *virFileFindResource(const char *filename, const char *builddir, --=20 2.40.1