From 5ca02655057bb568f09b3aed4acee44e3f805291 Mon Sep 17 00:00:00 2001 From: Niklas Hambüchen Date: Sun, 23 May 2021 16:59:43 +0200 Subject: libredirect: Add missing phase hooks --- pkgs/build-support/libredirect/default.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkgs/build-support/libredirect/default.nix b/pkgs/build-support/libredirect/default.nix index 4678d35442f61..b5836d1a3803a 100644 --- a/pkgs/build-support/libredirect/default.nix +++ b/pkgs/build-support/libredirect/default.nix @@ -14,6 +14,8 @@ stdenv.mkDerivation rec { outputs = ["out" "hook"]; buildPhase = '' + runHook preBuild + $CC -Wall -std=c99 -O3 -fPIC -ldl -shared \ ${lib.optionalString stdenv.isDarwin "-Wl,-install_name,$out/lib/$libName"} \ -o "$libName" \ @@ -22,9 +24,13 @@ stdenv.mkDerivation rec { if [ -n "$doInstallCheck" ]; then $CC -Wall -std=c99 -O3 test.c -o test fi + + runHook postBuild ''; installPhase = '' + runHook preInstall + install -vD "$libName" "$out/lib/$libName" mkdir -p "$hook/nix-support" @@ -36,6 +42,8 @@ stdenv.mkDerivation rec { export LD_PRELOAD="$out/lib/$libName" ''} SETUP_HOOK + + runHook postInstall ''; doInstallCheck = true; -- cgit 1.4.1 From 0afbd6c86a29160386e5386332b65ba707a25340 Mon Sep 17 00:00:00 2001 From: Niklas Hambüchen Date: Sun, 23 May 2021 16:25:52 +0200 Subject: libredirect: Enable debug symbols --- pkgs/build-support/libredirect/default.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/build-support/libredirect/default.nix b/pkgs/build-support/libredirect/default.nix index b5836d1a3803a..42525ec98a7e4 100644 --- a/pkgs/build-support/libredirect/default.nix +++ b/pkgs/build-support/libredirect/default.nix @@ -28,6 +28,11 @@ stdenv.mkDerivation rec { runHook postBuild ''; + # We want to retain debugging info to be able to use GDB on libredirect.so + # to more easily investigate which function overrides are missing or why + # existing ones do not have the intended effect. + dontStrip = true; + installPhase = '' runHook preInstall -- cgit 1.4.1 From 4961547d05376023fdc7a4664aba4d933d43e7b5 Mon Sep 17 00:00:00 2001 From: Niklas Hambüchen Date: Sun, 23 May 2021 16:26:34 +0200 Subject: libredirect: Fix redirects not working for subprocesses --- pkgs/build-support/libredirect/libredirect.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/libredirect/libredirect.c b/pkgs/build-support/libredirect/libredirect.c index dfa2978e9f440..5b0ef4856708c 100644 --- a/pkgs/build-support/libredirect/libredirect.c +++ b/pkgs/build-support/libredirect/libredirect.c @@ -17,15 +17,22 @@ static int nrRedirects = 0; static char * from[MAX_REDIRECTS]; static char * to[MAX_REDIRECTS]; +static int isInitialized = 0; + // FIXME: might run too late. static void init() __attribute__((constructor)); static void init() { + if (isInitialized) return; + char * spec = getenv("NIX_REDIRECTS"); if (!spec) return; - unsetenv("NIX_REDIRECTS"); + // Ensure we only run this code once. + // We do not do `unsetenv("NIX_REDIRECTS")` to ensure that redirects + // also get initialized for subprocesses. + isInitialized = 1; char * spec2 = malloc(strlen(spec) + 1); strcpy(spec2, spec); -- cgit 1.4.1 From fc5196c2f089e1483429aecd8dff56387a444e6b Mon Sep 17 00:00:00 2001 From: Pascal Bach Date: Fri, 3 Sep 2021 22:03:38 +0200 Subject: libredirect: add subprocess test --- pkgs/build-support/libredirect/test.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/libredirect/test.c b/pkgs/build-support/libredirect/test.c index 722d1303771c8..853f26bb52092 100644 --- a/pkgs/build-support/libredirect/test.c +++ b/pkgs/build-support/libredirect/test.c @@ -10,6 +10,7 @@ #include #define TESTPATH "/foo/bar/test" +#define SUBTEST "./test sub" extern char **environ; @@ -36,7 +37,11 @@ void test_system(void) { assert(system(TESTPATH) == 0); } -int main(void) +void test_subprocess(void) { + assert(system(SUBTEST) == 0); +} + +int main(int argc, char *argv[]) { FILE *testfp; int testfd; @@ -56,6 +61,14 @@ int main(void) test_spawn(); test_system(); + + // Only run subprocess if no arguments are given + // as the subprocess will be called without argument + // otherwise we will have infinite recursion + if (argc == 1) { + test_subprocess(); + } + test_execv(); /* If all goes well, this is never reached because test_execv() replaces -- cgit 1.4.1