From nobody Sun Jul 13 02:25:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525107859769187.43757669059096; Mon, 30 Apr 2018 10:04:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 360B5356C1; Mon, 30 Apr 2018 17:04:18 +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 8511B30012A8; Mon, 30 Apr 2018 17:04:17 +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 18F49180BAD4; Mon, 30 Apr 2018 17:04:17 +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 w3UGrAtd015815 for ; Mon, 30 Apr 2018 12:53:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9ABC22166BAE; Mon, 30 Apr 2018 16:53:10 +0000 (UTC) Received: from inaba.usersys.redhat.com (ovpn-204-197.brq.redhat.com [10.40.204.197]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F33012166BAD for ; Mon, 30 Apr 2018 16:53:09 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Mon, 30 Apr 2018 18:52:58 +0200 Message-Id: <20180430165303.6124-4-abologna@redhat.com> In-Reply-To: <20180430165303.6124-1-abologna@redhat.com> References: <20180430165303.6124-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/8] all: Use realpath() instead of canonicalize_file_name() 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 30 Apr 2018 17:04:18 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The latter is a glibc extension that's not available on other operating systems, notably FreeBSD. So far we have worked around the issue through gnulib, but that makes it difficult to use mocking in our test suite, so just drop it in favor of the portable alternative. Signed-off-by: Andrea Bolognani --- src/storage/storage_backend_fs.c | 2 +- src/util/virfile.c | 2 +- src/util/virpci.c | 2 +- tests/virstoragetest.c | 10 +++++----- tests/virtestmock.c | 13 ++++++------- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend= _fs.c index 9b0fcf92c5..37f02f0712 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -823,7 +823,7 @@ virStorageFileBackendFileGetUniqueIdentifier(virStorage= SourcePtr src) virStorageFileBackendFsPrivPtr priv =3D src->drv->priv; =20 if (!priv->canonpath) { - if (!(priv->canonpath =3D canonicalize_file_name(src->path))) { + if (!(priv->canonpath =3D realpath(src->path, NULL))) { virReportSystemError(errno, _("can't canonicalize path '%s'"), src->path); return NULL; diff --git a/src/util/virfile.c b/src/util/virfile.c index e12a584ca1..270906a009 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1597,7 +1597,7 @@ virFileResolveLinkHelper(const char *linkpath, return VIR_STRDUP_QUIET(*resultpath, linkpath) < 0 ? -1 : 0; } =20 - *resultpath =3D canonicalize_file_name(linkpath); + *resultpath =3D realpath(linkpath, NULL); =20 return *resultpath =3D=3D NULL ? -1 : 0; } diff --git a/src/util/virpci.c b/src/util/virpci.c index 23932558e9..1108d2a7c1 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2622,7 +2622,7 @@ virPCIGetDeviceAddressFromSysfsLink(const char *devic= e_link) return NULL; } =20 - device_path =3D canonicalize_file_name(device_link); + device_path =3D realpath(device_link, NULL); if (device_path =3D=3D NULL) { virReportSystemError(errno, _("Failed to resolve device link '%s'"), diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index b032d8b93f..ff95292698 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -171,7 +171,7 @@ testPrepImages(void) fprintf(stderr, "unable to create directory %s\n", datadir "/dir"); goto cleanup; } - if (!(canondir =3D canonicalize_file_name(absdir))) { + if (!(canondir =3D realpath(absdir, NULL))) { virReportOOMError(); goto cleanup; } @@ -186,7 +186,7 @@ testPrepImages(void) fprintf(stderr, "unable to create raw file\n"); goto cleanup; } - if (!(canonraw =3D canonicalize_file_name(absraw))) { + if (!(canonraw =3D realpath(absraw, NULL))) { virReportOOMError(); goto cleanup; } @@ -206,7 +206,7 @@ testPrepImages(void) "-F", "raw", "-b", "raw", "qcow2", NULL); if (virCommandRun(cmd, NULL) < 0) goto skip; - if (!(canonqcow2 =3D canonicalize_file_name(absqcow2))) { + if (!(canonqcow2 =3D realpath(absqcow2, NULL))) { virReportOOMError(); goto cleanup; } @@ -220,7 +220,7 @@ testPrepImages(void) virCommandAddArg(cmd, "wrap"); if (virCommandRun(cmd, NULL) < 0) goto skip; - if (!(canonwrap =3D canonicalize_file_name(abswrap))) { + if (!(canonwrap =3D realpath(abswrap, NULL))) { virReportOOMError(); goto cleanup; } @@ -233,7 +233,7 @@ testPrepImages(void) virCommandAddArg(cmd, "qed"); if (virCommandRun(cmd, NULL) < 0) goto skip; - if (!(canonqed =3D canonicalize_file_name(absqed))) { + if (!(canonqed =3D realpath(absqed, NULL))) { virReportOOMError(); goto cleanup; } diff --git a/tests/virtestmock.c b/tests/virtestmock.c index 688945d805..9dcff1bd75 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -133,12 +133,11 @@ checkPath(const char *path) virAsprintfQuiet(&relPath, "./%s", path) < 0) goto error; =20 - /* Le sigh. Both canonicalize_file_name() and realpath() - * expect @path to exist otherwise they return an error. So - * if we are called over an non-existent file, this could - * return an error. In that case do our best and hope we will - * catch possible error. */ - if ((fullPath =3D canonicalize_file_name(relPath ? relPath : path))) { + /* Le sigh. realpath() expects @path to exist, otherwise it will + * return an error. So if we are called over an non-existent file, + * this could return an error. In that case do our best and hope we + * will catch possible errors. */ + if ((fullPath =3D realpath(relPath ? relPath : path, NULL))) { path =3D fullPath; } else { /* Yeah, our worst nightmares just became true. Path does @@ -148,7 +147,7 @@ checkPath(const char *path) =20 virFileRemoveLastComponent(crippledPath); =20 - if ((fullPath =3D canonicalize_file_name(crippledPath))) + if ((fullPath =3D realpath(crippledPath, NULL))) path =3D fullPath; } =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list