From 9141f48ea551c1538bbab17c44c8f9e8393b5679 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 28 Dec 2014 18:14:34 +0100 Subject: [PATCH] test: fix spawn test with autotools build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix spawn_reads_child_path when executed as `test/run-tests` or `make check`: 1. `make check` builds a dynamic libuv.so or libuv.dyld by default. 2. spawn_reads_child_path spawns a new instance of the test runner by consulting uv_exepath() and executing the result. 3. `test/run-tests` is normally a shell script that sets up DYLD_LIBRARY_PATH or LD_LIBRARY_PATH before executing the real test runner in `test/.libs`. 4. uv_exepath() (corectly) returns the path of the binary in `test/.libs`. The binary is linked against libuv.so but that library is not on any of the default linker paths; and if it is, it's almost certainly the wrong version. 5. Ergo, carry over the value of the (DY)LD_LIBRARY_PATH environment variable into the environment of the child process so that the dynamic linker knows where to find the library. Alternatively, we could link the test runner statically against libuv.a but that breaks `make check` when configured with `--disable-static`. Fixes: https://github.com/libuv/libuv/issues/85 PR-URL: https://github.com/libuv/libuv/pull/91 Reviewed-By: Saúl Ibarra Corretgé --- test/test-spawn.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/test-spawn.c b/test/test-spawn.c index f9d13d1f..5c25f819 100644 --- a/test/test-spawn.c +++ b/test/test-spawn.c @@ -1300,7 +1300,16 @@ TEST_IMPL(spawn_reads_child_path) { int len; char file[64]; char path[1024]; - char *env[2] = {path, NULL}; + char* env[3]; + + /* Need to carry over the dynamic linker path when the test runner is + * linked against libuv.so, see https://github.com/libuv/libuv/issues/85. + */ +#if defined(__APPLE__) + static const char dyld_path_var[] = "DYLD_LIBRARY_PATH"; +#else + static const char dyld_path_var[] = "LD_LIBRARY_PATH"; +#endif /* Set up the process, but make sure that the file to run is relative and */ /* requires a lookup into PATH */ @@ -1315,6 +1324,16 @@ TEST_IMPL(spawn_reads_child_path) { strcpy(path, "PATH="); strcpy(path + 5, exepath); + env[0] = path; + env[1] = getenv(dyld_path_var); + env[2] = NULL; + + if (env[1] != NULL) { + static char buf[1024 + sizeof(dyld_path_var)]; + snprintf(buf, sizeof(buf), "%s=%s", dyld_path_var, env[1]); + env[1] = buf; + } + options.file = file; options.args[0] = file; options.env = env;