diff --git a/pkgs/build-support/libredirect/default.nix b/pkgs/build-support/libredirect/default.nix index 5545c93c19e1..9a35db97c9ff 100644 --- a/pkgs/build-support/libredirect/default.nix +++ b/pkgs/build-support/libredirect/default.nix @@ -57,7 +57,7 @@ else stdenv.mkDerivation rec { ''} if [ -n "$doInstallCheck" ]; then - $CC -Wall -std=c99 -O3 test.c -o test + $CC -Wall -std=c99 -D_POSIX_C_SOURCE=200809L -O3 test.c -o test fi runHook postBuild @@ -91,7 +91,7 @@ else stdenv.mkDerivation rec { installCheckPhase = '' ( source "$hook/nix-support/setup-hook" - NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true" ./test + NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true:/bar/baz=$(mktemp -d)" ./test ) ''; diff --git a/pkgs/build-support/libredirect/libredirect.c b/pkgs/build-support/libredirect/libredirect.c index 0dc7feb382c3..e33199402c4b 100644 --- a/pkgs/build-support/libredirect/libredirect.c +++ b/pkgs/build-support/libredirect/libredirect.c @@ -354,3 +354,27 @@ WRAPPER(int, mkdirat)(int dirfd, const char *path, mode_t mode) return mkdirat_real(dirfd, rewrite(path, buf), mode); } WRAPPER_DEF(mkdirat) + +WRAPPER(int, unlink)(const char *path) +{ + int (*unlink_real) (const char *path) = LOOKUP_REAL(unlink); + char buf[PATH_MAX]; + return unlink_real(rewrite(path, buf)); +} +WRAPPER_DEF(unlink) + +WRAPPER(int, unlinkat)(int dirfd, const char *path, int flags) +{ + int (*unlinkat_real) (int dirfd, const char *path, int flags) = LOOKUP_REAL(unlinkat); + char buf[PATH_MAX]; + return unlinkat_real(dirfd, rewrite(path, buf), flags); +} +WRAPPER_DEF(unlinkat) + +WRAPPER(int, rmdir)(const char *path) +{ + int (*rmdir_real) (const char *path) = LOOKUP_REAL(rmdir); + char buf[PATH_MAX]; + return rmdir_real(rewrite(path, buf)); +} +WRAPPER_DEF(rmdir) diff --git a/pkgs/build-support/libredirect/test.c b/pkgs/build-support/libredirect/test.c index 853f26bb5209..c546a8958288 100644 --- a/pkgs/build-support/libredirect/test.c +++ b/pkgs/build-support/libredirect/test.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -9,6 +10,7 @@ #include #include +#define TESTDIR "/bar/baz" #define TESTPATH "/foo/bar/test" #define SUBTEST "./test sub" @@ -59,6 +61,22 @@ int main(int argc, char *argv[]) assert(stat(TESTPATH, &testsb) != -1); + assert(mkdir(TESTDIR "/dir-mkdir", 0777) == 0); + assert(unlink(TESTDIR "/dir-mkdir") == -1); // it's a directory! +#ifndef __APPLE__ + assert(errno == EISDIR); +#endif + assert(rmdir(TESTDIR "/dir-mkdir") == 0); + assert(unlink(TESTDIR "/dir-mkdir") == -1); + assert(errno == ENOENT); + + assert(mkdirat(123, TESTDIR "/dir-mkdirat", 0777) == 0); + assert(unlinkat(123, TESTDIR "/dir-mkdirat", 0) == -1); // it's a directory! +#ifndef __APPLE__ + assert(errno == EISDIR); +#endif + assert(unlinkat(123, TESTDIR "/dir-mkdirat", AT_REMOVEDIR) == 0); + test_spawn(); test_system();