From nobody Wed May 14 12:42:37 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 1525107287511848.6022154138759; Mon, 30 Apr 2018 09:54:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B10CD3003A5D; Mon, 30 Apr 2018 16:54:44 +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 7947987B0; Mon, 30 Apr 2018 16:54:44 +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 1E9A64CAAD; Mon, 30 Apr 2018 16:54:44 +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 w3UGr98g015810 for ; Mon, 30 Apr 2018 12:53:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8E2E02166BAE; Mon, 30 Apr 2018 16:53:09 +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 E85972166BAD for ; Mon, 30 Apr 2018 16:53:08 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Mon, 30 Apr 2018 18:52:57 +0200 Message-Id: <20180430165303.6124-3-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 2/8] tests: Mock realpath() 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.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 30 Apr 2018 16:54:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We need to use VIR_MOCK_REAL_INIT_VERSIONED() and ask for a specific version of the symbol here, because the implementation dlsym() returns by default on Linux is unsuitable for our use. Signed-off-by: Andrea Bolognani --- tests/virpcimock.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 176c64d654..9a5e6b4cec 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -43,6 +43,7 @@ static char *(*real_canonicalize_file_name)(const char *p= ath); static int (*real_open)(const char *path, int flags, ...); static int (*real_close)(int fd); static DIR * (*real_opendir)(const char *name); +static char *(*real_realpath)(const char *path, char *resolved); =20 /* Don't make static, since it causes problems with clang * when passed as an arg to virAsprintf() @@ -814,6 +815,20 @@ init_syms(void) VIR_MOCK_REAL_INIT(open); VIR_MOCK_REAL_INIT(close); VIR_MOCK_REAL_INIT(opendir); + + /* When linking on Linux, the default implementation of realpath() is + * realpath@GLIBC_2.3; when using dlsym(), however, we get the older + * realpath@GLIBC_2.2.5 instead, which unfortunately doesn't support + * passing NULL as the second parameter. + * + * Ask for a versioned symbol to make sure we get a working realpath() + * on Linux; other operating systems such as FreeBSD don't suffer from + * the same limitation and can rely on the default dlsym() behavior */ +# ifdef __linux__ + VIR_MOCK_REAL_INIT_VERSIONED(realpath, "GLIBC_2.3"); +# else + VIR_MOCK_REAL_INIT(realpath); +# endif } =20 static void @@ -1046,6 +1061,25 @@ close(int fd) return -1; return real_close(fd); } + +char * +realpath(const char *path, char *resolved) +{ + char *ret; + + init_syms(); + + if (STRPREFIX(path, SYSFS_PCI_PREFIX)) { + char *newpath; + if (getrealpath(&newpath, path) < 0) + return NULL; + ret =3D real_realpath(newpath, resolved); + VIR_FREE(newpath); + } else { + ret =3D real_realpath(path, resolved); + } + return ret; +} #else /* Nothing to override on non-__linux__ platforms */ #endif --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list