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 (1 of 1 file). Show all

Unified · Split

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