[libvirt] [PATCH] tests: Put a mock library at the start of LD_PRELOAD

This fixes vircgrouptest when run in a sandbox which already overrides open() and others. --- tests/testutils.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/testutils.h b/tests/testutils.h index 27af5da..8583747 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -87,8 +87,9 @@ int virtTestMain(int argc, perror(lib); \ return EXIT_FAILURE; \ } \ - if (virAsprintf(&newenv, "%s%s%s", preload ? preload : "", \ - preload ? ":" : "", lib) < 0) { \ + if (!preload) { \ + newenv = (char *) lib; \ + } else if (virAsprintf(&newenv, "%s:%s", lib, preload) < 0) { \ perror("virAsprintf"); \ return EXIT_FAILURE; \ } \ -- 1.8.3.2

On Tue, Jul 30, 2013 at 11:29:11AM +0200, Jiri Denemark wrote:
This fixes vircgrouptest when run in a sandbox which already overrides open() and others.
In general I think that having multiple LD_PRELOADS overriding the same symbols may well lead to pain. We try to make it at least chain up the libraries by using the 'RTLD_NEXT' handle when looking up the "real" symbol, which should make it forward to the next preloaded library. From the sound of it, your sandbox tool isn't using RTLD_NEXT, causing the libvirt override to be skipped when the order was reversed.
--- tests/testutils.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tests/testutils.h b/tests/testutils.h index 27af5da..8583747 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -87,8 +87,9 @@ int virtTestMain(int argc, perror(lib); \ return EXIT_FAILURE; \ } \ - if (virAsprintf(&newenv, "%s%s%s", preload ? preload : "", \ - preload ? ":" : "", lib) < 0) { \ + if (!preload) { \ + newenv = (char *) lib; \ + } else if (virAsprintf(&newenv, "%s:%s", lib, preload) < 0) { \ perror("virAsprintf"); \ return EXIT_FAILURE; \ } \
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Tue, Jul 30, 2013 at 10:37:40 +0100, Daniel Berrange wrote:
On Tue, Jul 30, 2013 at 11:29:11AM +0200, Jiri Denemark wrote:
This fixes vircgrouptest when run in a sandbox which already overrides open() and others.
In general I think that having multiple LD_PRELOADS overriding the same symbols may well lead to pain.
We try to make it at least chain up the libraries by using the 'RTLD_NEXT' handle when looking up the "real" symbol, which should make it forward to the next preloaded library. From the sound of it, your sandbox tool isn't using RTLD_NEXT, causing the libvirt override to be skipped when the order was reversed.
I did some investigation and the sandbox actually uses RTLD_NEXT but unfortunately searches for full symbols including their versions. Thus, e.g., our implementation of fopen() is ignored because the sandbox wants fopen@GLIBC_2.2.5.
ACK
Thanks and pushed. Jirka
participants (2)
-
Daniel P. Berrange
-
Jiri Denemark