History

livepatch/klp-build: add grep-override function

Provide a custom grep() function to catch direct usage of the command. Bare grep calls are generally incompatible with pipefail and errexit behavior (where a failed match causes the script to exit). Developers can still call grep via command grep if that behavior is explicitly desired.

Joe Lawrence committed 8 months ago

Commit e4dbf701 parent d36a7341 file · +7 −0Browse files

Showing the changes to scripts/livepatch (1 of 1 file). Show all

Unified · Split

scripts/livepatch/klp-build+7−0
@@ -56,6 +56,13 @@ grep0() { · 55 unmodified lines
56 command grep "$@" || true56 command grep "$@" || true
57}57}
58 58
59# Because pipefail is enabled, the grep0 helper should be used instead of
60# grep, otherwise a failed match can propagate to an error.
61grep() {
62 echo "error: $SCRIPT: use grep0 or 'command grep' instead of bare grep" >&2
63 exit 1
64}
65
59status() {66status() {
60 echo "$*"67 echo "$*"
61}68}