From de0612c46cf17a368e92eaac91fd94affbe36488 Mon Sep 17 00:00:00 2001 From: Danylo Hlynskyi Date: Wed, 20 Mar 2019 14:57:59 +0200 Subject: [PATCH] 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. --- pkgs/build-support/setup-hooks/auto-patchelf.sh | 11 +++++++---- 1 file 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)