Skip to content

Commit

Permalink
auto-patchelf: don't use grep -q, as it causes Broken pipe (#56958)
Browse files Browse the repository at this point in the history
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:
#55566 (comment)

I hope, replacing `grep -q` with `grep` will remove this race condition.
  • Loading branch information
danbst committed Mar 20, 2019
1 parent 52c3ee6 commit de0612c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkgs/build-support/setup-hooks/auto-patchelf.sh
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit de0612c

Please sign in to comment.