Skip to content

eBPF-based security platform

docs: check the options of a shirudo command split over lines

John Fastabendd711f866f119
diff --git a/.github/scripts/check-docs.sh b/.github/scripts/check-docs.sh
index e2b1716e..020697c6 100755
--- a/.github/scripts/check-docs.sh
+++ b/.github/scripts/check-docs.sh
@@ -34,9 +34,25 @@ report() {
find Documentation -name '*.rst' -not -path 'Documentation/output*' \
-not -path 'Documentation/contribute/code/coding-style.rst' | sort >"$work/pages"
-# The options of the command lines in console blocks, by page.
+# The options of the command lines in console blocks, by page. A command
+# line ending in a backslash is joined to the next, as the shell does,
+# and so is one with blanks after the backslash, which a reader pastes
+# all the same. Only a command is joined: a backslash that ends any
+# other line of a page would take the prompt of the next one with it,
+# and a command ends at the next prompt or blank line whatever it ends
+# in, as that one starts another.
while IFS= read -r page; do
- grep -E '^[[:space:]]+(operator\$|target#|\$|#) shirudo( |$)' "$page" |
+ awk '
+ joined && /^[ \t]*$|^[ \t]+(operator\$|target#|\$|#) / {
+ print ""
+ joined = 0
+ }
+ !joined && !/^[ \t]+(operator\$|target#|\$|#) shirudo( |$)/ { next }
+ {
+ joined = sub(/\\[ \t]*$/, "")
+ printf "%s%s", $0, joined ? "" : "\n"
+ }
+ END { if (joined) print "" }' "$page" |
grep -oE -- '--[a-z0-9][a-z0-9-]*' | sort -u |
sed "s|^|$page |"
done <"$work/pages" >"$work/options"
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index 10e0f13a..86bd0546 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -84,11 +84,14 @@ signed config image.
outside the list or named like one on it, and the operator
binaries when built
* - ``t0008-check-docs``
- - ``check-docs.sh``: the whole of each field of a threat's fact
- box, a hook by its section, each tamper and integrity counter's
- entry on its page, the source files a proof reads or the proof
- coverage page lists as read by none, a figure against its TikZ
- source and one without a source, and the tree itself
+ - ``check-docs.sh``: an option on a continuation line of a
+ console example, with blanks after its backslash, a command
+ after a line that is none and a prompt or blank line that ends
+ one, the whole of each field of a threat's fact box, a hook by
+ its section, each tamper and integrity counter's entry on its
+ page, the source files a proof reads or the proof coverage page
+ lists as read by none, a figure against its TikZ source and one
+ without a source, and the tree itself
* - ``t0009-check-unused``
- ``check-unused.sh``: an extern function nothing calls, with its
type on its line or the one above, a header's declaration that is
diff --git a/testing/ci-checks/t0008-check-docs.sh b/testing/ci-checks/t0008-check-docs.sh
index 3f3832c8..97347dbe 100755
--- a/testing/ci-checks/t0008-check-docs.sh
+++ b/testing/ci-checks/t0008-check-docs.sh
@@ -2,7 +2,8 @@
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Authors of shirudo
#
-# t0008 -- .github/scripts/check-docs.sh: the whole of each field of a
+# t0008 -- .github/scripts/check-docs.sh: the options of a console
+# example on every line of its command, the whole of each field of a
# threat's fact box, a hook by its section, the programs and counters no
# threat names, the source files a proof reads or the coverage page
# lists as read by none, and a figure against its TikZ source, on a
@@ -32,7 +33,7 @@ put() {
good() {
rm -rf "$R" && mkdir -p "$R" && git init -q "$R" &&
put shirudo.c 'int main(void) { return 0; }' &&
- put builtin-upatch.c 'int upatch;' &&
+ put builtin-upatch.c 'static const char *option = "--json";' &&
put tools/shirudo-build/build.c 'int build;' &&
put tools/gen-image/gen '#!/bin/sh' &&
put tools/gen-initrd/gen '#!/bin/sh' &&
@@ -84,6 +85,33 @@ test_expect_success 'a tree whose fields continue on a second line passes' '
good && check
'
+# A page whose console block holds the given lines.
+console() {
+ put Documentation/start/run.rst '.. code-block:: console' '' "$@"
+}
+
+test_expect_success 'an option on a continuation line of a command is checked' '
+ good && console " \$ shirudo status \\" " --json" &&
+ check &&
+ good && console " \$ shirudo status \\" " --bogus" &&
+ refuses "no parser accepts --bogus" &&
+ good && console " \$ shirudo status \\ " " --bogus" &&
+ refuses "no parser accepts --bogus"
+'
+
+test_expect_success 'only the lines of a shirudo command are checked' '
+ good && console " \$ shirudo status --json" " --bogus" &&
+ check &&
+ good && console " \$ make --bogus \\" " --bogus" &&
+ check &&
+ good && console " \$ make \\" " \$ shirudo status --bogus" &&
+ refuses "no parser accepts --bogus" &&
+ good && console " \$ shirudo status \\" " \$ make --bogus" &&
+ check &&
+ good && console " \$ shirudo status \\" "" " --bogus" &&
+ check
+'
+
test_expect_success 'a hook on a continuation line is checked, by its section' '
good && sed -i "s|lsm.s/inode_setattr|lsm.s/inode_setattrx|" "$R/$TM" &&
refuses "no BPF program has the section lsm.s/inode_setattrx" &&