2020-02-19 08:34:42 -07:00
|
|
|
#!/usr/bin/gawk -f
|
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
# Script to check sysctl documentation against source files
|
|
|
|
#
|
|
|
|
# Copyright (c) 2020 Stephen Kitt
|
|
|
|
|
|
|
|
# Example invocation:
|
|
|
|
# scripts/check-sysctl-docs -vtable="kernel" \
|
|
|
|
# Documentation/admin-guide/sysctl/kernel.rst \
|
2024-02-19 13:19:22 -07:00
|
|
|
# $(git grep -l register_sysctl)
|
2020-02-19 08:34:42 -07:00
|
|
|
#
|
|
|
|
# Specify -vdebug=1 to see debugging information
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
if (!table) {
|
|
|
|
print "Please specify the table to look for using the table variable" > "/dev/stderr"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# The following globals are used:
|
|
|
|
# documented: maps documented entries (each key is an entry)
|
|
|
|
# entries: maps ctl_table names and procnames to counts (so
|
|
|
|
# enumerating the subkeys for a given ctl_table lists its
|
|
|
|
# procnames)
|
|
|
|
# curtable: the name of the current ctl_table struct
|
|
|
|
# curentry: the name of the current proc entry (procname when parsing
|
|
|
|
# a ctl_table, constructed path when parsing a ctl_path)
|
|
|
|
|
|
|
|
|
|
|
|
# Remove punctuation from the given value
|
|
|
|
function trimpunct(value) {
|
|
|
|
while (value ~ /^["&]/) {
|
|
|
|
value = substr(value, 2)
|
|
|
|
}
|
|
|
|
while (value ~ /[]["&,}]$/) {
|
|
|
|
value = substr(value, 1, length(value) - 1)
|
|
|
|
}
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
|
|
|
|
# Print the information for the given entry
|
|
|
|
function printentry(entry) {
|
|
|
|
seen[entry]++
|
|
|
|
printf "* %s from %s", entry, file[entry]
|
|
|
|
if (documented[entry]) {
|
|
|
|
printf " (documented)"
|
|
|
|
}
|
|
|
|
print ""
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Stage 1: build the list of documented entries
|
|
|
|
FNR == NR && /^=+$/ {
|
|
|
|
if (prevline ~ /Documentation for/) {
|
|
|
|
# This is the main title
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
|
|
|
# The previous line is a section title, parse it
|
|
|
|
$0 = prevline
|
|
|
|
if (debug) print "Parsing " $0
|
|
|
|
inbrackets = 0
|
|
|
|
for (i = 1; i <= NF; i++) {
|
|
|
|
if (length($i) == 0) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if (!inbrackets && substr($i, 1, 1) == "(") {
|
|
|
|
inbrackets = 1
|
|
|
|
}
|
|
|
|
if (!inbrackets) {
|
|
|
|
token = trimpunct($i)
|
|
|
|
if (length(token) > 0 && token != "and") {
|
|
|
|
if (debug) print trimpunct($i)
|
|
|
|
documented[trimpunct($i)]++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (inbrackets && substr($i, length($i), 1) == ")") {
|
|
|
|
inbrackets = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FNR == NR {
|
|
|
|
prevline = $0
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Stage 2: process each file and find all sysctl tables
|
|
|
|
BEGINFILE {
|
|
|
|
delete entries
|
|
|
|
curtable = ""
|
|
|
|
curentry = ""
|
2024-02-19 13:19:24 -07:00
|
|
|
delete vars
|
2020-02-19 08:34:42 -07:00
|
|
|
if (debug) print "Processing file " FILENAME
|
|
|
|
}
|
|
|
|
|
2024-02-19 13:19:22 -07:00
|
|
|
/^static( const)? struct ctl_table/ {
|
|
|
|
match($0, /static( const)? struct ctl_table ([^][]+)/, tables)
|
|
|
|
curtable = tables[2]
|
2020-02-19 08:34:42 -07:00
|
|
|
if (debug) print "Processing table " curtable
|
|
|
|
}
|
|
|
|
|
|
|
|
/^};$/ {
|
|
|
|
curtable = ""
|
|
|
|
curentry = ""
|
2024-02-19 13:19:24 -07:00
|
|
|
delete vars
|
2020-02-19 08:34:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
curtable && /\.procname[\t ]*=[\t ]*".+"/ {
|
|
|
|
match($0, /.procname[\t ]*=[\t ]*"([^"]+)"/, names)
|
|
|
|
curentry = names[1]
|
|
|
|
if (debug) print "Adding entry " curentry " to table " curtable
|
|
|
|
entries[curtable][curentry]++
|
|
|
|
file[curentry] = FILENAME
|
|
|
|
}
|
|
|
|
|
2024-02-19 13:19:22 -07:00
|
|
|
/register_sysctl.*/ {
|
|
|
|
match($0, /register_sysctl(|_init|_sz)\("([^"]+)" *, *([^,)]+)/, tables)
|
|
|
|
if (debug) print "Registering table " tables[3] " at " tables[2]
|
|
|
|
if (tables[2] == table) {
|
|
|
|
for (entry in entries[tables[3]]) {
|
|
|
|
printentry(entry)
|
|
|
|
}
|
|
|
|
}
|
2020-02-19 08:34:42 -07:00
|
|
|
}
|
|
|
|
|
2024-02-19 13:19:24 -07:00
|
|
|
/kmemdup.*/ {
|
|
|
|
match($0, /([^ \t]+) *= *kmemdup\(([^,]+) *,/, names)
|
|
|
|
if (debug) print "Found variable " names[1] " for table " names[2]
|
|
|
|
if (names[2] in entries) {
|
|
|
|
vars[names[1]] = names[2]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/__register_sysctl_table.*/ {
|
|
|
|
match($0, /__register_sysctl_table\([^,]+, *"([^"]+)" *, *([^,]+)/, tables)
|
|
|
|
if (debug) print "Registering variable table " tables[2] " at " tables[1]
|
|
|
|
if (tables[1] == table && tables[2] in vars) {
|
|
|
|
for (entry in entries[vars[tables[2]]]) {
|
|
|
|
printentry(entry)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-19 08:34:42 -07:00
|
|
|
END {
|
|
|
|
for (entry in documented) {
|
|
|
|
if (!seen[entry]) {
|
|
|
|
print "No implementation for " entry
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|