summary refs log tree commit diff
path: root/pkgs/build-support/build-fhs-userenv
diff options
context:
space:
mode:
authorLas <las@protonmail.ch>2019-05-26 17:19:06 +0200
committerGitHub <noreply@github.com>2019-05-26 17:19:06 +0200
commit50c215df4af77575ffde2d31980ff5bbe39c3d65 (patch)
treeabf50a33bffa015abbe323f910a7baa76ac375c7 /pkgs/build-support/build-fhs-userenv
parent567b63c78feb2bb0591f9b6ec64b1e94487aeadf (diff)
downloadnixpkgs-50c215df4af77575ffde2d31980ff5bbe39c3d65.tar
nixpkgs-50c215df4af77575ffde2d31980ff5bbe39c3d65.tar.gz
nixpkgs-50c215df4af77575ffde2d31980ff5bbe39c3d65.tar.bz2
nixpkgs-50c215df4af77575ffde2d31980ff5bbe39c3d65.tar.lz
nixpkgs-50c215df4af77575ffde2d31980ff5bbe39c3d65.tar.xz
nixpkgs-50c215df4af77575ffde2d31980ff5bbe39c3d65.tar.zst
nixpkgs-50c215df4af77575ffde2d31980ff5bbe39c3d65.zip
Fix chrootenv segfaulting on exit
glibc 2.27 (and possibly other versions) can't handle an `nopenfd` value larger than 2^19 in `ntfw`, which is problematic if you've set the maximum number of fds per process to a value higher than that.
Diffstat (limited to 'pkgs/build-support/build-fhs-userenv')
-rw-r--r--pkgs/build-support/build-fhs-userenv/chrootenv/chrootenv.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/pkgs/build-support/build-fhs-userenv/chrootenv/chrootenv.c b/pkgs/build-support/build-fhs-userenv/chrootenv/chrootenv.c
index 0e9e36bc301..34e050dde4f 100644
--- a/pkgs/build-support/build-fhs-userenv/chrootenv/chrootenv.c
+++ b/pkgs/build-support/build-fhs-userenv/chrootenv/chrootenv.c
@@ -19,6 +19,10 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
+int min(int a, int b) {
+  return a > b ? b : a;
+}
+
 const gchar *bind_blacklist[] = {"bin", "etc", "host", "usr", "lib", "lib64", "lib32", "sbin", NULL};
 
 void bind_mount(const gchar *source, const gchar *target) {
@@ -126,7 +130,9 @@ int main(gint argc, gchar **argv) {
     int status;
 
     fail_if(waitpid(cpid, &status, 0) != cpid);
-    fail_if(nftw(prefix, nftw_remove, getdtablesize(),
+    // glibc 2.27 (and possibly other versions) can't handle
+    // an nopenfd value larger than 2^19
+    fail_if(nftw(prefix, nftw_remove, min(getdtablesize(), 1<<19),
                  FTW_DEPTH | FTW_MOUNT | FTW_PHYS));
 
     if (WIFEXITED(status))