eBPF-based security platform
docs: check only shirudo's own options in a console example
John Fastabendbc5669534e73
diff --git a/.github/scripts/check-docs.sh b/.github/scripts/check-docs.shindex 020697c6..c06ab34b 100755--- a/.github/scripts/check-docs.sh+++ b/.github/scripts/check-docs.sh@@ -37,22 +37,107 @@ find Documentation -name '*.rst' -not -path 'Documentation/output*' \# 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+# all the same, and one that ends inside a quote or a substitution or+# after a pipe. 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.+# in, as that one starts another. What a command hands to another+# program, after a pipe, in a list or in a substitution, is not+# shirudo's, and neither is a comment; a quote hides all of these, and+# so does a placeholder such as <a|b>.while IFS= read -r page; doawk '- joined && /^[ \t]*$|^[ \t]+(operator\$|target#|\$|#) / {- print ""+ # What of a command line shirudo runs, and in unfinished whether+ # the line ends where the shell would read on. keep[d] says whether+ # the command at nesting depth d is shirudo, quoted[d] whether it+ # stands in double quotes there, and closing[d] what ends the depth.+ function shirudo_only(line, c, d, from, i, len, next_c, prev_c,+ start, text) {+ sub(/^[ \t]+[a-z]*[$#] /, "", line)+ len = length(line)+ d = 0+ quoted[0] = 0+ closing[0] = ""+ start = 1+ for (i = 1; i <= len; i++) {+ c = substr(line, i, 1)+ next_c = substr(line, i + 1, 1)+ prev_c = i > 1 ? substr(line, i - 1, 1) : " "+ if (start) {+ keep[d] = substr(line, i) ~ /^[ \t]*shirudo( |$)/+ start = 0+ }+ if (c == "\\") {+ i+++ } else if (c == "\047" && !quoted[d]) {+ from = ++i+ while (i <= len && substr(line, i, 1) != "\047")+ i+++ if (i > len) {+ unfinished = 1+ return text+ }+ if (keep[d])+ text = text substr(line, from, i - from)+ } else if (c == "\"") {+ quoted[d] = !quoted[d]+ } else if (d && !quoted[d] && c == closing[d]) {+ d--+ text = text " "+ } else if (c == "$" && next_c == "(" || c == "`" ||+ c == "(" && !quoted[d]) {+ if (c == "$")+ i+++ d+++ closing[d] = c == "`" ? "`" : ")"+ quoted[d] = 0+ start = 1+ text = text " "+ } else if (quoted[d]) {+ if (keep[d])+ text = text c+ } else if (match(substr(line, i), /^<[^ \t\n<>]+>/)) {+ if (keep[d])+ text = text substr(line, i, RLENGTH)+ i += RLENGTH - 1+ } else if (c == "#" && prev_c ~ /[ \t\n]/) {+ while (i < len && next_c != "\n") {+ i+++ next_c = substr(line, i + 1, 1)+ }+ } else if (c == "|" || c == ";" || c == "\n" ||+ c == "&" && prev_c !~ /[<>]/ && next_c != ">") {+ if (next_c == c && c != ";")+ i+++ start = 1+ text = text " "+ } else if (keep[d]) {+ text = text c+ }+ }+ unfinished = d || quoted[0] || line ~ /(\||&&)[ \t]*$/+ return text+ }+ function finish() {+ print shirudo_only(command)+ command = ""joined = 0}+ joined && /^[ \t]*$|^[ \t]+(operator\$|target#|\$|#) / { finish() }!joined && !/^[ \t]+(operator\$|target#|\$|#) shirudo( |$)/ { next }{- joined = sub(/\\[ \t]*$/, "")- printf "%s%s", $0, joined ? "" : "\n"+ continued = sub(/\\[ \t]*$/, "")+ command = command $0+ if (!continued) {+ shirudo_only(command)+ if (unfinished)+ command = command "\n"+ }+ joined = continued || unfinished+ if (!joined)+ finish()}- END { if (joined) print "" }' "$page" |+ END { if (joined) finish() }' "$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.rstindex 86bd0546..d3acf388 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -87,11 +87,16 @@ signed config image.- ``check-docs.sh``: an option on a continuation line of aconsole example, with blanks after its backslash, a commandafter 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+ one, the options of a program a command pipes to, runs next or+ substitutes and of a comment, which are not shirudo's, a pipe,+ list or comment inside a quote or a placeholder, a shirudo+ command behind a pipe or in a substitution, one that goes on+ after a line ending inside a substitution, 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 itstype on its line or the one above, a header's declaration that isdiff --git a/testing/ci-checks/t0008-check-docs.sh b/testing/ci-checks/t0008-check-docs.shindex 97347dbe..0c979c4e 100755--- a/testing/ci-checks/t0008-check-docs.sh+++ b/testing/ci-checks/t0008-check-docs.sh@@ -3,12 +3,11 @@# Copyright (c) 2026 Authors of shirudo## 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-# throwaway repository, and the tree itself.-+# example on every line of its command and none of another program's,+# 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 throwaway repository, and the tree itself.cd "$(dirname "$0")/..". ./test-lib.shcommand -v git >/dev/null 2>&1 || test_skip_all "git not installed"@@ -112,6 +111,81 @@ test_expect_success 'only the lines of a shirudo command are checked' 'check'+q="'"++test_expect_success 'what a command hands to another program is not checked' '+ good && console " \$ shirudo status --json \\" " | jq --arg k v" &&+ check &&+ good && console " \$ shirudo status && ls --color; ls --all" &&+ check &&+ good && console " \$ shirudo status & ls --color" &&+ check &&+ good && console " \$ shirudo status --json # --bogus" &&+ check &&+ good && console " \$ shirudo status > \"\$(mktemp --tmpdir)\"" &&+ check &&+ good && console " \$ shirudo status | grep -c \"\$(hostname)\" --color" &&+ check &&+ good && console " \$ shirudo status | jq -r $q.a | select(.b)$q --arg k v" &&+ check+'++test_expect_success 'a quote hides a pipe, a list and a comment, and a redirect is none' '+ good && console " \$ shirudo status \"a|b\" --bogus" &&+ refuses "no parser accepts --bogus" &&+ good && console " \$ shirudo status \"a; b\" --bogus" &&+ refuses "no parser accepts --bogus" &&+ good && console " \$ shirudo status \"a #b\" --bogus" &&+ refuses "no parser accepts --bogus" &&+ good && console " \$ shirudo status ${q}a | b$q --bogus" &&+ refuses "no parser accepts --bogus" &&+ good && console " \$ shirudo status $q--bogus$q \"--json\"" &&+ refuses "no parser accepts --bogus" &&+ good && console " \$ shirudo status | jq $q--bogus$q" &&+ check &&+ good && console " \$ shirudo status \`ls | wc -l\` --bogus" &&+ refuses "no parser accepts --bogus" &&+ good && console " \$ shirudo status 2>&1 --bogus" &&+ refuses "no parser accepts --bogus" &&+ good && console " \$ shirudo status <&3 --bogus" &&+ refuses "no parser accepts --bogus"+'++test_expect_success 'a placeholder hides a pipe, a list and a parenthesis' '+ good && console " \$ shirudo status <a|b> --bogus" &&+ refuses "no parser accepts --bogus" &&+ good && console " \$ shirudo status <a;b> <c&d> <e(f)> --bogus" &&+ refuses "no parser accepts --bogus" &&+ good && console " \$ shirudo status <in | jq --arg k v >out" &&+ check+'++test_expect_success 'a shirudo command behind another is checked' '+ good && console " \$ shirudo status | shirudo status --bogus" &&+ refuses "no parser accepts --bogus" &&+ good && console " \$ ls || shirudo status --bogus" &&+ check &&+ good && console " \$ shirudo status || shirudo status --bogus" &&+ refuses "no parser accepts --bogus" &&+ good && console " \$ shirudo status \"\$(shirudo status --bogus | jq -r .a)\"" &&+ refuses "no parser accepts --bogus" &&+ good && console " \$ shirudo status \"\$(ls | jq --arg k v)\" --bogus" &&+ refuses "no parser accepts --bogus"+'++test_expect_success 'a command that ends inside a substitution goes on' '+ good && console " \$ shirudo status \\" \+ " \"\$(shirudo status --json |" \+ " jq --arg k v)\" \\" " --json" &&+ check &&+ good && console " \$ shirudo status \\" \+ " \"\$(shirudo status --json |" \+ " jq --arg k v)\" \\" " --bogus" &&+ refuses "no parser accepts --bogus" &&+ good && console " \$ shirudo status \"\$(ls" " \$ make --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" &&