From nobody Sun Feb 8 17:21:34 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1623046300; cv=none; d=zohomail.com; s=zohoarc; b=jK1riYpvphXniIlvUDPdwWNpHTc5uMyDG89aiC9p9/lVuerKP4K6ExWqUh+mM4xqX4p9uX1o4A8dfOPWgifi9VHN3tiAHyzqBGKmFmyiILXfRPwRJDHotg8J+KvWobH7bER7Aet9ei/qDwY5jvkJtVNnYBcZA78WwxvDXZ+viX0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623046300; 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=jcusGCvm09WJrkrV5uQrn+4XMKUCMizRku8o5hFryc0=; b=OSEPxw3I+m83joALcYhSNDjcW1DhFrF311avE/BCaxn1TGPQWeb5lJg04CAOW0aIU+XhA3ZjI/vwCDomGOC5l519mOX/YfDB9imOpaFlvluUia/GKq7eu9UcCziklvSnvw5d+0evgYID83SNiMTz7X7kY0XAQ5dofaI1kJ8nqXY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail 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 1623046300207937.1339949501939; Sun, 6 Jun 2021 23:11:40 -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-595-8o_D1y8gN_iKrDAyNwhPnA-1; Mon, 07 Jun 2021 02:11:37 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 022CA107ACF2; Mon, 7 Jun 2021 06:11:32 +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 D5C2D610DF; Mon, 7 Jun 2021 06:11: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 9D24C1800BB8; Mon, 7 Jun 2021 06:11:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1576B8QS019638 for ; Mon, 7 Jun 2021 02:11:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5A123345B1; Mon, 7 Jun 2021 06:11:08 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D9EE345AC for ; Mon, 7 Jun 2021 06:11:06 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E6F9D1857F2D for ; Mon, 7 Jun 2021 06:11:05 +0000 (UTC) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-298-azRKw8ubPeCh01HYy7BxhA-1; Mon, 07 Jun 2021 02:11:03 -0400 Received: by mail-pl1-f176.google.com with SMTP id x10so8054023plg.3 for ; Sun, 06 Jun 2021 23:11:03 -0700 (PDT) Received: from localhost ([38.94.108.250]) by smtp.gmail.com with ESMTPSA id j13sm3833750pgp.29.2021.06.06.23.11.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Jun 2021 23:11:02 -0700 (PDT) X-MC-Unique: 8o_D1y8gN_iKrDAyNwhPnA-1 X-MC-Unique: azRKw8ubPeCh01HYy7BxhA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jcusGCvm09WJrkrV5uQrn+4XMKUCMizRku8o5hFryc0=; b=REbW7fB+6aWPTOOGimMB36NkFSn+RRJ5NikN9tzIdHEUtvvRC/vTuB+WL2K9cZ0jOF d9SSHNuG9OWR/lBMJJF4bqYcOl1nPGSAKDdVr715xa27THn8ztdAMKl2SrGoD1OGAYdS ooxq0HkS1h0R5247454YJmKldrMsuYJDA45V4iEGBvD4RR7ktrrQfDZTgTGwnjcBV5DV 6KQ8mfL7AIHU5mBA0YcPIO4YZgm0/4xEgl1tWl2PrFYR4917oNtJnMWCW/oQylvU5rnM KNI1hc7/d9Fd9Q6aTYQMDpURI6QNZ6HdAUH43K7WpruFf5C6xKGQo11HWc1Ux949WAFG m4Dw== X-Gm-Message-State: AOAM532lKYz34YLTe1VZY29YDuFHZl5lG7fRQEyWYJ9FeX3xCuAHs9kd aDWa6P6jLu4y73/ntkuJnPPbvXzsURcrTaaVRj8= X-Google-Smtp-Source: ABdhPJwCpCsQe60g9loNzMzvPANxAH5vMOUFawqqfDjCpBCD/dQHaRdx0ipKaBKqbNryoAPHModO3g== X-Received: by 2002:a17:90a:578a:: with SMTP id g10mr30281493pji.165.1623046262476; Sun, 06 Jun 2021 23:11:02 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH 2/2] virfile: Simplify virFindFileInPath() with g_find_program_in_path() Date: Mon, 7 Jun 2021 14:10:48 +0800 Message-Id: <20210607061048.124496-3-lukedyue@gmail.com> In-Reply-To: <20210607061048.124496-1-lukedyue@gmail.com> References: <20210607061048.124496-1-lukedyue@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 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.12 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 Content-Type: text/plain; charset="utf-8" Signed-off-by: Luke Yue Reviewed-by: Martin Kletzander --- src/util/virfile.c | 48 +++------------------------------------------- 1 file changed, 3 insertions(+), 45 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 7fe357ab16..14b45f4e1b 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1662,55 +1662,13 @@ virFileIsLink(const char *linkpath) char * virFindFileInPath(const char *file) { - const char *origpath =3D NULL; - g_auto(GStrv) paths =3D NULL; - char **pathiter; - + g_autofree char *path =3D NULL; if (file =3D=3D NULL) return NULL; =20 - /* if we are passed an absolute path (starting with /), return a - * copy of that path, after validating that it is executable - */ - if (g_path_is_absolute(file)) { - if (!virFileIsExecutable(file)) - return NULL; - - return g_strdup(file); - } - - /* If we are passed an anchored path (containing a /), then there - * is no path search - it must exist in the current directory - */ - if (strchr(file, '/')) { - char *abspath =3D NULL; - - if (!virFileIsExecutable(file)) - return NULL; - - ignore_value(abspath =3D g_canonicalize_filename(file, NULL)); - return abspath; - } + path =3D g_find_program_in_path(file); =20 - /* copy PATH env so we can tweak it */ - origpath =3D getenv("PATH"); - if (!origpath) - origpath =3D "/bin:/usr/bin"; - - /* for each path segment, append the file to search for and test for - * it. return it if found. - */ - - if (!(paths =3D g_strsplit(origpath, ":", 0))) - return NULL; - - for (pathiter =3D paths; *pathiter; pathiter++) { - g_autofree char *fullpath =3D g_build_filename(*pathiter, file, NU= LL); - if (virFileIsExecutable(fullpath)) - return g_steal_pointer(&fullpath); - } - - return NULL; + return g_canonicalize_filename(path, NULL); } =20 =20 --=20 2.31.1