From nobody Tue Feb 10 05:10:48 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=1622425757; cv=none; d=zohomail.com; s=zohoarc; b=L5qjIJ08xM+N/ESLm6YXFVgvAydbVVuIpzM8rMTM8cP/ZRNnUHEMV8rxlQ3NNjEd+UvKDitHa1yjZV8xkaGyZAFwBgxcvxkCxjjSpZp6CoQkjGkoEeJ0vtBSqPeXYBVx9aaexjx/HRvnsUI4rye5f/4S21U/VH84bs3M/jXBxxw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622425757; 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=J+kNVVJXPbKkjTUdSEP5uyyfWFf4DaXwsZ5U7F3NLxw=; b=G1EAYfaV5xUguUCJdbTsR8qAR5aimiEiioLYL2b4vMxqy3bLE30QnU9QZCxyCJevUg79eA2FWPO7BupSKPutOQYvycbCTUkiwNApKk2Sl/w3FCJa8gTjkCJPGgSkXBby8Qb+PW+q52hw0stG7dRHDqFNoSlw4jo/nq2kJtsXMbw= 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 162242575783257.765973872991935; Sun, 30 May 2021 18:49:17 -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-245-AwClidT4MwijeP88us61-Q-1; Sun, 30 May 2021 21:49:14 -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 6704C180FD61; Mon, 31 May 2021 01:49:08 +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 487B0687C7; Mon, 31 May 2021 01:49:08 +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 0D3095534B; Mon, 31 May 2021 01:49:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14V1mh4C007357 for ; Sun, 30 May 2021 21:48:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id D95F8200D8CE; Mon, 31 May 2021 01:48:43 +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 D4EB4200D8CD for ; Mon, 31 May 2021 01:48:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (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 BC1B11857F28 for ; Mon, 31 May 2021 01:48:43 +0000 (UTC) Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-575-LeMFpAquNDOwjez2rVlsIA-1; Sun, 30 May 2021 21:48:40 -0400 Received: by mail-pj1-f52.google.com with SMTP id g6-20020a17090adac6b029015d1a9a6f1aso9543097pjx.1 for ; Sun, 30 May 2021 18:48:40 -0700 (PDT) Received: from localhost ([103.138.53.238]) by smtp.gmail.com with ESMTPSA id z6sm10136471pgp.89.2021.05.30.18.48.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 May 2021 18:48:39 -0700 (PDT) X-MC-Unique: AwClidT4MwijeP88us61-Q-1 X-MC-Unique: LeMFpAquNDOwjez2rVlsIA-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=J+kNVVJXPbKkjTUdSEP5uyyfWFf4DaXwsZ5U7F3NLxw=; b=fVeEiYIDhVsynk43dx90RqCA6ieflonSjEA/CdNT0FLmZJE6dWK7nEbJ3iO/oWDqSA faGhem4nrjrcSdNjPdwwZxsQFrDJMP4RmGrs9nVXDdsxguGSXRn09CiZSw0XHxdwTMm/ 1nD7FgcgbHyAVLwVPTuKlprW97X2YT95FkZd0HhyrBOlayBTM9QwbDHoPWq4txAZs4iJ TWHwMyLDU4FGu5369Kf66g4xfBQ11cSbGWK8ZOBBSRqaN5NUQIr9rK0HtMmePju2lL49 xHPSWOkYIVbhJvbvMBNIBpqZBNoNL4JtQ4PVArHwsvPOgjkCYMJadp1U3uf9F4SKtyu/ oucA== X-Gm-Message-State: AOAM532gRF5ugHT/yJOj3canhCz5MAozUeIVa3bxLR6Ceg/HHsfHJhVB V90JnFyno3Ntk0tN2/zoAFBhjTa7BuKZxE0u/cg= X-Google-Smtp-Source: ABdhPJxvyeNw+CxEwxrsULgc1EoDqw6mZYdCHnIy5nYGYI6i5vK0dcq6oEKwD6AcjR9zwjyrzzFRXg== X-Received: by 2002:a17:90a:5b0c:: with SMTP id o12mr9242394pji.108.1622425719694; Sun, 30 May 2021 18:48:39 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH 2/3] virfile: Simplify virFindFileInPath() with g_find_program_in_path() Date: Mon, 31 May 2021 09:48:23 +0800 Message-Id: <20210531014824.923662-3-lukedyue@gmail.com> In-Reply-To: <20210531014824.923662-1-lukedyue@gmail.com> References: <20210531014824.923662-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.78 on 10.11.54.4 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 Content-Type: text/plain; charset="utf-8" The behavior is a little bit different when using g_find_program_in_path(), when the `file` contains a relative path, the original function would return a absolute path, but the g_find_program_in_path() would probably return a relative one. Other conditions would be fine, so just use g_find_program_in_path() to simplify the implementation. Note that when PATH is not set, g_find_program_in_path() will search in `/bin:/usr/bin:.`. Signed-off-by: Luke Yue --- src/util/virfile.c | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index dc2834fd1c..0d1c2ba518 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1662,27 +1662,14 @@ virFileIsLink(const char *linkpath) char * virFindFileInPath(const char *file) { - const char *origpath =3D NULL; - g_auto(GStrv) paths =3D NULL; - char **pathiter; - 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 we are passed an anchored path (containing a /), and it's not an + * absolute path then there is no path search - it must exist in the c= urrent + * directory */ - if (strchr(file, '/')) { + if (!g_path_is_absolute(file) && strchr(file, '/')) { char *abspath =3D NULL; =20 if (!virFileIsExecutable(file)) @@ -1692,25 +1679,8 @@ virFindFileInPath(const char *file) return abspath; } =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; + /* Otherwise, just use g_find_program_in_path() */ + return g_find_program_in_path(file); } =20 =20 --=20 2.31.1