Skip to content

eBPF-based security platform

.github: ask a silent source for the checkpatch scripts only once

Martynas Pumputis9614f8deeb2f
diff --git a/.github/scripts/check-style.sh b/.github/scripts/check-style.sh
index fd15c008..2dd88858 100755
--- a/.github/scripts/check-style.sh
+++ b/.github/scripts/check-style.sh
@@ -131,21 +131,39 @@ verified() {
[ -f "$1" ] && [ "$(sha256sum "$1" | cut -d' ' -f1)" = "$2" ]
}
+# Where the kernel's scripts come from, in the order they are asked. A
+# source that fails one script is not asked for the next, so a host that
+# does not answer costs its retries once rather than once per script.
+fetch_sources='kernel.org github'
+
+source_url() {
+ case $1 in
+ kernel.org)
+ printf '%s\n' "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/scripts/$2?h=$KERNEL_TAG"
+ ;;
+ github)
+ printf '%s\n' "https://raw.githubusercontent.com/torvalds/linux/$KERNEL_TAG/scripts/$2"
+ ;;
+ esac
+}
+
# Fetch one of the kernel's scripts at the pinned tag, from kernel.org or
-# its GitHub mirror, and keep it only when it hashes as expected.
+# its GitHub mirror, and keep it only when it hashes as expected. Without
+# a connect timeout curl waits out the system's TCP one, over two minutes
+# an attempt, on a host that drops what it is sent.
fetch() {
name=$1
sum=$2
dest=$3
- for url in \
- "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/scripts/$name?h=$KERNEL_TAG" \
- "https://raw.githubusercontent.com/torvalds/linux/$KERNEL_TAG/scripts/$name"; do
- if curl -fsSL --retry 3 -o "$dest.tmp" "$url" &&
+ for source in $fetch_sources; do
+ if curl -fsSL --connect-timeout 10 --max-time 60 --retry 3 \
+ -o "$dest.tmp" "$(source_url "$source" "$name")" &&
verified "$dest.tmp" "$sum"; then
mv "$dest.tmp" "$dest"
return 0
fi
rm -f "$dest.tmp"
+ fetch_sources=${fetch_sources#*"$source"}
done
die "could not fetch scripts/$name at $KERNEL_TAG with sha256 $sum"
}
diff --git a/Documentation/contribute/code/developer-guide.rst b/Documentation/contribute/code/developer-guide.rst
index 0451dc13..566d3a43 100644
--- a/Documentation/contribute/code/developer-guide.rst
+++ b/Documentation/contribute/code/developer-guide.rst
@@ -567,7 +567,9 @@ the commit at ``HEAD`` alone without them.
:doc:`/contribute/testing/proofs`.
``check-style.sh`` fetches the kernel's ``checkpatch.pl`` at a pinned
-tag into ``build/checkpatch/`` and verifies its SHA-256. Set
+tag into ``build/checkpatch/`` and verifies its SHA-256. It asks
+kernel.org first and then its GitHub mirror, gives each ten seconds to
+answer, and does not ask again a source that failed once. Set
``CHECKPATCH=<path>`` to use a kernel tree's
``scripts/checkpatch.pl`` instead, for example without network access.
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index 81a91cf7..e4d1cffd 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -43,7 +43,8 @@ signed config image.
* - ``t0003-check-style``
- ``check-style.sh``: checkpatch at 100 columns, the block-comment
opener, the subject length, the integer, parser, copy and
- format rules
+ format rules, and a fetch of ``checkpatch.pl`` that asks a host
+ which does not answer only once
* - ``t0004-ci-commit-range``
- ``ci-commit-range.sh``: the ranges for a pull request, a push and
a force push
diff --git a/testing/ci-checks/t0003-check-style.sh b/testing/ci-checks/t0003-check-style.sh
index 475eec17..ff692c0b 100644
--- a/testing/ci-checks/t0003-check-style.sh
+++ b/testing/ci-checks/t0003-check-style.sh
@@ -7,7 +7,8 @@
# opener and the subject length the wrapper adds, the message of a commit
# that touches no C, the sources it leaves alone, the userspace spellings
# it lets through, the C library's integer names, number parsers and
-# string copies it refuses and the list of what stays enabled, on a
+# string copies it refuses, the list of what stays enabled, and the fetch
+# of checkpatch.pl, which asks a host that does not answer only once, on a
# throwaway repository.
cd "$(dirname "$0")/.."
@@ -299,4 +300,48 @@ test_expect_success '--diff checks the uncommitted changes' '
grep -q "no uncommitted changes" "$W/out"
'
+# A curl to which kernel.org does not answer, as curl reports a timeout,
+# and which serves the GitHub mirror from the copy the tests run with:
+# only that copy at the pinned tag can stand in for the mirror.
+P=$(dirname "$CHECKPATCH")
+pinned() {
+ [ "$(sha256sum "$P/$2" 2>/dev/null | cut -d' ' -f1)" = \
+ "$(sed -n "s/^$1=//p" "$S")" ]
+}
+mkdir -p "$W/bin"
+cat >"$W/bin/curl" <<'EOF'
+#!/bin/sh
+printf '%s\n' "$*" >>"$CURL_LOG"
+out=
+while [ $# -gt 1 ]; do
+ [ "$1" = -o ] && out=$2
+ shift
+done
+case $1 in
+https://raw.githubusercontent.com/*)
+ cp "$PINNED/${1##*/}" "$out"
+ ;;
+*)
+ exit 28
+ ;;
+esac
+EOF
+chmod +x "$W/bin/curl"
+
+if pinned CHECKPATCH_PL_SHA256 checkpatch.pl &&
+ pinned SPELLING_SHA256 spelling.txt &&
+ pinned CONST_STRUCTS_SHA256 const_structs.checkpatch; then
+test_expect_success 'a source that does not answer is asked once, then the mirror' '
+ rm -rf "$R/build/checkpatch" "$W/curl.log" &&
+ (cd "$R" && PATH="$W/bin:$PATH" CURL_LOG="$W/curl.log" PINNED="$P" \
+ CHECKPATCH= sh "$S" --types) >"$W/out" 2>"$W/err" &&
+ [ "$(grep -c "https://git.kernel.org/" "$W/curl.log")" -eq 1 ] &&
+ [ "$(grep -c "https://raw.githubusercontent.com/" "$W/curl.log")" -eq 3 ] &&
+ ! grep -v -e "--connect-timeout" "$W/curl.log" &&
+ for f in checkpatch.pl spelling.txt const_structs.checkpatch; do
+ cmp -s "$P/$f" "$R/build/checkpatch/$f" || exit 1
+ done
+'
+fi
+
test_done