[libvirt] [PATCH v2 3/8] all: Use realpath() instead of canonicalize_file_name()

Andrea Bolognani abologna at redhat.com
Wed May 2 16:42:41 UTC 2018


On Wed, 2018-05-02 at 17:32 +0100, Daniel P. Berrangé wrote:
> On Mon, Apr 30, 2018 at 06:52:58PM +0200, Andrea Bolognani wrote:
> > 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.
> 
> Sigh, unfortunately realpath() has its own portability problems
> in that passing NULL as second arg was a glibc invention, which
> is why we switched from realpath() to canonicalize_file_name()
> in the first place !
> 
> So I wonder if this actually works on OS-X, Mingw and FreeBSD,
> or whether you didn't see the bug because it is mocked in the
> tests ?

The FreeBSD[1] and macOS[2] releases we care about ship a sensible
implementation of realpath(), which explicitly allows passing NULL
as the second parameter.

Not sure about MinGW, but doesn't it ship basically a recompiled
version of glibc? If so, I would expect it to be perfectly fine
too.

I should also note that I've successfully run the test suite, with
these changes applied, on all CI platforms, so we know there's no
Linux distribution we care about shipping an old enough glibc that
wouldn't include a reasonable realpath().

As for the mocking hiding the issue, we end up calling the actual
realpath() at the end of the day, just on a different file... So
I wouldn't expect that to invalidate the results.


[1] https://www.freebsd.org/cgi/man.cgi?query=realpath&apropos=0&sektion=3&manpath=FreeBSD+10.4-RELEASE&arch=default&format=html
[2] https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/realpath.3.html
-- 
Andrea Bolognani / Red Hat / Virtualization




More information about the libvir-list mailing list