From nobody Fri May 3 08:10:59 2024 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=1623046278; cv=none; d=zohomail.com; s=zohoarc; b=bDu6f8MhkS5TDYdLtt8vvv6Cuv3PWDX2+TnlFSBh2n9XlMtXydqrApIuuIPSRrIaLRk0QJ3c4vkkjCYGce1jOuVFGBE2WzPZbn4ihHRWzS2w+qwPkoeRtcoyhk20LCeFPSqY11xSwIJgsBaHczANsJcuTKBIy1tTqacNNdmaMkI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623046278; 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=z1F07M3hwbGsFi2BQJ31fxVEyb6xG4dFURxtCig/HLg=; b=PNyjGz2eIujVNGKkQ3Xy4JSvQ+j4aJ64GYV0So6Zm91RrWTENnbD3jx2p0n+hZnsIrzC6hD2eDK5LLZSq5NWZOTKAgbN0B5XhA4JJgzOeGYDsPWk2SZfrrM+2zHyl6LW4BI8/JANkQD9yVKzgDhJ1+eqLmgtfvfOo7u2MLuH0A8= 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 1623046277999794.9931732281079; Sun, 6 Jun 2021 23:11: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-313-44vQud_tMwWCdxIss2HkVQ-1; Mon, 07 Jun 2021 02:11:14 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E07ED107ACF8; Mon, 7 Jun 2021 06:11: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 B81811037E80; Mon, 7 Jun 2021 06:11: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 5D3F84E9E2; Mon, 7 Jun 2021 06:11:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1576B6wL019628 for ; Mon, 7 Jun 2021 02:11:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5DD902162381; Mon, 7 Jun 2021 06:11:06 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 535822162395 for ; Mon, 7 Jun 2021 06:11:01 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.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 B72B2101D221 for ; Mon, 7 Jun 2021 06:11:01 +0000 (UTC) Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-507-wODviIr4PCWBzfcEZZ7Cpw-1; Mon, 07 Jun 2021 02:10:59 -0400 Received: by mail-pj1-f48.google.com with SMTP id md2-20020a17090b23c2b029016de4440381so2414991pjb.1 for ; Sun, 06 Jun 2021 23:10:59 -0700 (PDT) Received: from localhost ([38.94.108.250]) by smtp.gmail.com with ESMTPSA id s24sm11396270pju.9.2021.06.06.23.10.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Jun 2021 23:10:57 -0700 (PDT) X-MC-Unique: 44vQud_tMwWCdxIss2HkVQ-1 X-MC-Unique: wODviIr4PCWBzfcEZZ7Cpw-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=z1F07M3hwbGsFi2BQJ31fxVEyb6xG4dFURxtCig/HLg=; b=nnAjo7D1+DIsVPmbcUn/Wpzzgogg7au9Msr7LzjV1deAndF+57bH192oOR8f5EUKyt j1tCP+EgRbQLd62w2Dez7Lo0fuRCe5aJXpl/cywD/QSAeCJa1WglChikBpTdzhLrUEqR EQrE+CLGzxeA4dgYXikbxcTzC/2eWEx2GALy3dtIm3Y0kUIzZS0F3ZXVlVTMCnjsH3lT MJmbqDxMsDN+iQheQw66Gu1tKlUBrblqr/1Z/1uaBGvtNLyiBT12su064M9t1rGTGlyc r5FqTe6hPpWLA5ysMJDxT+R2AlsmvKE/HnfznqbgmiCHMhF3xBR/S2otxQ9L7tWoT6A7 bJNA== X-Gm-Message-State: AOAM530bDP3rvVGpo4ey0+iCJx2dL8QLBoZk2Stzi4kYPvXeKKjaSa5C ztESL4lAAe8qC0zOs99S6BkEqMVFNN3Bm59Vqa0= X-Google-Smtp-Source: ABdhPJw9uvDx5QL33sBBoGkxRdk8BQ+GFtOS6MXoQ5DquWCoalsaDrjTItb/vO71B7TZLHwxIRNXtQ== X-Received: by 2002:a17:902:6acb:b029:fc:4d8c:cfba with SMTP id i11-20020a1709026acbb02900fc4d8ccfbamr16561158plt.29.1623046257990; Sun, 06 Jun 2021 23:10:57 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH 1/2] Replace virFileAbsPath() with g_canonicalize_filename() Date: Mon, 7 Jun 2021 14:10:47 +0800 Message-Id: <20210607061048.124496-2-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.78 on 10.11.54.6 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.84 on 10.5.11.22 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/libvirt-domain.c | 16 ++++++++-------- src/libvirt_private.syms | 1 - src/util/virfile.c | 23 +---------------------- src/util/virfile.h | 3 --- src/util/virlog.c | 2 +- 5 files changed, 10 insertions(+), 35 deletions(-) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 42c75f6cc5..750e32f0ca 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -827,7 +827,7 @@ virDomainSave(virDomainPtr domain, const char *to) char *absolute_to; =20 /* We must absolutize the file path as the save is done out of pro= cess */ - if (virFileAbsPath(to, &absolute_to) < 0) { + if (!(absolute_to =3D g_canonicalize_filename(to, NULL))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("could not build absolute output file path")); goto error; @@ -915,7 +915,7 @@ virDomainSaveFlags(virDomainPtr domain, const char *to, char *absolute_to; =20 /* We must absolutize the file path as the save is done out of pro= cess */ - if (virFileAbsPath(to, &absolute_to) < 0) { + if (!(absolute_to =3D g_canonicalize_filename(to, NULL))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("could not build absolute output file path")); goto error; @@ -965,7 +965,7 @@ virDomainRestore(virConnectPtr conn, const char *from) char *absolute_from; =20 /* We must absolutize the file path as the restore is done out of = process */ - if (virFileAbsPath(from, &absolute_from) < 0) { + if (!(absolute_from =3D g_canonicalize_filename(from, NULL))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("could not build absolute input file path")); goto error; @@ -1039,7 +1039,7 @@ virDomainRestoreFlags(virConnectPtr conn, const char = *from, const char *dxml, char *absolute_from; =20 /* We must absolutize the file path as the restore is done out of = process */ - if (virFileAbsPath(from, &absolute_from) < 0) { + if (!(absolute_from =3D g_canonicalize_filename(from, NULL))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("could not build absolute input file path")); goto error; @@ -1097,7 +1097,7 @@ virDomainSaveImageGetXMLDesc(virConnectPtr conn, cons= t char *file, char *absolute_file; =20 /* We must absolutize the file path as the read is done out of pro= cess */ - if (virFileAbsPath(file, &absolute_file) < 0) { + if (!(absolute_file =3D g_canonicalize_filename(file, NULL))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("could not build absolute input file path")); goto error; @@ -1170,7 +1170,7 @@ virDomainSaveImageDefineXML(virConnectPtr conn, const= char *file, char *absolute_file; =20 /* We must absolutize the file path as the read is done out of pro= cess */ - if (virFileAbsPath(file, &absolute_file) < 0) { + if (!(absolute_file =3D g_canonicalize_filename(file, NULL))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("could not build absolute input file path")); goto error; @@ -1245,7 +1245,7 @@ virDomainCoreDump(virDomainPtr domain, const char *to= , unsigned int flags) char *absolute_to; =20 /* We must absolutize the file path as the save is done out of pro= cess */ - if (virFileAbsPath(to, &absolute_to) < 0) { + if (!(absolute_to =3D g_canonicalize_filename(to, NULL))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("could not build absolute core file path")); goto error; @@ -1329,7 +1329,7 @@ virDomainCoreDumpWithFormat(virDomainPtr domain, cons= t char *to, char *absolute_to; =20 /* We must absolutize the file path as the save is done out of pro= cess */ - if (virFileAbsPath(to, &absolute_to) < 0) { + if (!(absolute_to =3D g_canonicalize_filename(to, NULL))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("could not build absolute core file path")); goto error; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0ced2a7990..e4b2d386f7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2176,7 +2176,6 @@ virDirOpen; virDirOpenIfExists; virDirOpenQuiet; virDirRead; -virFileAbsPath; virFileAccessibleAs; virFileActivateDirOverrideForLib; virFileActivateDirOverrideForProg; diff --git a/src/util/virfile.c b/src/util/virfile.c index f32f3e37e4..7fe357ab16 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1688,7 +1688,7 @@ virFindFileInPath(const char *file) if (!virFileIsExecutable(file)) return NULL; =20 - ignore_value(virFileAbsPath(file, &abspath)); + ignore_value(abspath =3D g_canonicalize_filename(file, NULL)); return abspath; } =20 @@ -3146,27 +3146,6 @@ virFileOpenTty(int *ttyprimary G_GNUC_UNUSED, } #endif /* WIN32 */ =20 -/* - * Creates an absolute path for a potentially relative path. - * Return 0 if the path was not relative, or on success. - * Return -1 on error. - * - * You must free the result. - */ -int -virFileAbsPath(const char *path, char **abspath) -{ - if (g_path_is_absolute(path)) { - *abspath =3D g_strdup(path); - } else { - g_autofree char *buf =3D g_get_current_dir(); - - *abspath =3D g_build_filename(buf, path, NULL); - } - - return 0; -} - /* Remove spurious / characters from a path. The result must be freed */ char * virFileSanitizePath(const char *path) diff --git a/src/util/virfile.h b/src/util/virfile.h index b9f7b1766f..72368495bf 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -283,9 +283,6 @@ char *virFileBuildPath(const char *dir, const char *name, const char *ext) G_GNUC_WARN_UNUSED_RESULT; =20 - -int virFileAbsPath(const char *path, - char **abspath) G_GNUC_WARN_UNUSED_RESULT; void virFileRemoveLastComponent(char *path); =20 int virFileOpenTty(int *ttymaster, diff --git a/src/util/virlog.c b/src/util/virlog.c index 78be1993cd..3ad043d98a 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -1512,7 +1512,7 @@ virLogParseOutput(const char *src) #endif break; case VIR_LOG_TO_FILE: - if (virFileAbsPath(tokens[2], &abspath) < 0) + if (!(abspath =3D g_canonicalize_filename(tokens[2], NULL))) return NULL; ret =3D virLogNewOutputToFile(prio, abspath); VIR_FREE(abspath); --=20 2.31.1 From nobody Fri May 3 08:10:59 2024 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