about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorDanylo Hlynskyi <abcz2.uprola@gmail.com>2019-03-20 14:57:59 +0200
committerGitHub <noreply@github.com>2019-03-20 14:57:59 +0200
commitde0612c46cf17a368e92eaac91fd94affbe36488 (patch)
treeeb034846c2a9950c6dc624d7faba6bfd9d69b307 /pkgs/build-support
parent52c3ee6c4d3fac1ad0a7aff0788abda639d8b3fc (diff)
downloadnixlib-de0612c46cf17a368e92eaac91fd94affbe36488.tar
nixlib-de0612c46cf17a368e92eaac91fd94affbe36488.tar.gz
nixlib-de0612c46cf17a368e92eaac91fd94affbe36488.tar.bz2
nixlib-de0612c46cf17a368e92eaac91fd94affbe36488.tar.lz
nixlib-de0612c46cf17a368e92eaac91fd94affbe36488.tar.xz
nixlib-de0612c46cf17a368e92eaac91fd94affbe36488.tar.zst
nixlib-de0612c46cf17a368e92eaac91fd94affbe36488.zip
auto-patchelf: don't use grep -q, as it causes Broken pipe (#56958)
This rare sitation was caught when building zoom-us package:
```
automatically fixing dependencies for ELF files
/nix/store/71d65fplq44y9yn2fvkpn2d3hrszracd-auto-patchelf-hook/nix-support/setup-hook: line 213: echo: write error: Broken pipe
/nix/store/71d65fplq44y9yn2fvkpn2d3hrszracd-auto-patchelf-hook/nix-support/setup-hook: line 210: echo: write error: Broken pipe
```

The worst is that derivation continued and resulted into broken package:
https://github.com/NixOS/nixpkgs/pull/55566#issuecomment-470065690

I hope, replacing `grep -q` with `grep` will remove this race condition.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/setup-hooks/auto-patchelf.sh11
1 files changed, 7 insertions, 4 deletions
diff --git a/pkgs/build-support/setup-hooks/auto-patchelf.sh b/pkgs/build-support/setup-hooks/auto-patchelf.sh
index 5bedd1a9f9ca..6af8eb1aed99 100644
--- a/pkgs/build-support/setup-hooks/auto-patchelf.sh
+++ b/pkgs/build-support/setup-hooks/auto-patchelf.sh
@@ -15,8 +15,10 @@ isExecutable() {
     # *or* there is an INTERP section. This also catches position-independent
     # executables, as they typically have an INTERP section but their ELF type
     # is DYN.
-    LANG=C readelf -h -l "$1" 2> /dev/null \
-        | grep -q '^ *Type: *EXEC\>\|^ *INTERP\>'
+    isExeResult="$(LANG=C readelf -h -l "$1" 2> /dev/null \
+        | grep '^ *Type: *EXEC\>\|^ *INTERP\>')"
+    # not using grep -q, because it can cause Broken pipe
+    [ -n "$isExeResult" ]
 }
 
 # We cache dependencies so that we don't need to search through all of them on
@@ -207,10 +209,11 @@ autoPatchelf() {
       isELF "$file" || continue
       segmentHeaders="$(LANG=C readelf -l "$file")"
       # Skip if the ELF file doesn't have segment headers (eg. object files).
-      echo "$segmentHeaders" | grep -q '^Program Headers:' || continue
+      # not using grep -q, because it can cause Broken pipe
+      [ -n "$(echo "$segmentHeaders" | grep '^Program Headers:')" ] || continue
       if isExecutable "$file"; then
           # Skip if the executable is statically linked.
-          echo "$segmentHeaders" | grep -q "^ *INTERP\\>" || continue
+          [ -n "$(echo "$segmentHeaders" | grep "^ *INTERP\\>")" ] || continue
       fi
       autoPatchelfFile "$file"
     done < <(find "$@" ${norecurse:+-maxdepth 1} -type f -print0)