Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5870101ybv; Tue, 18 Feb 2020 05:37:02 -0800 (PST) X-Google-Smtp-Source: APXvYqzr2D08I6j+4fHO087HYjykteD14gbzPZMerZ/WjeShYfhQGSCNrjVXB1pgNg0+m4YRvYMU X-Received: by 2002:a05:6830:1149:: with SMTP id x9mr16201769otq.156.1582033022175; Tue, 18 Feb 2020 05:37:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582033022; cv=none; d=google.com; s=arc-20160816; b=qhaWQGpAXm2jWyjArjstaXffTQdpwDojBaALTfYvmRYLX69D0a6Jkgrf8Z15pz2KV9 CcpEvAM3JbjtMF+iaHpbL4Dv0C70h4zqUaB53bTCNuiHG2Fuo8kluQMrDY/8BJ1VejRL rq4RNesWJMwmdWJuKh0gMWzoChc4szyf0ifOBc3M1Ng/1TomDbS2OQ+z3AxaPOaIqwEL strc9kWJeQIyKcJipu+dPin+B3lFiOY6rwAG6QdaZGvJAKpypK7rXSHsdAPZtOKF0/lc 8As8a+bj14+cL2uNvDj5Irgmb3RYAR698ZXWtVNnazkorKJ82KKsoOHJsk6VA4pSCGct hHqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jxzOOb4s6beo/FcBKjLqaaqreGkwrpr2I8n2i3r6Sxo=; b=DwXqxLDCYohruySUhAN3Cj3h/+VP5/KDs4yxJ5fCF2RJadkmzOSg8utHEllK+w1V4I Z7NMlyIvh9uTjooXivobex2HWc2Rh4x8NY7cBQ3CnKyZcwSQJbvXUaeiwXfOUnEiO0U9 A6MLGqzMjDPAqfyxCy41GbRmb9yq889fm0xXdWxtq0lggXMTSa2aB4sxLVmQ+qDRsDF+ kXGDvoxJ0wwPKBwpnXlzFUc/UiwUB9OpPmGCcBn2ygMtqaUPHOcypnnrM5ruBdz4limG yZpwB+cgPUueqsr1E473ccacA/GdtcKCcGBFmH+7sEr+AmV4Ump/Op3W0ft2d01KkiZl Fs+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d199si8451958oib.135.2020.02.18.05.36.49; Tue, 18 Feb 2020 05:37:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726546AbgBRNgP (ORCPT + 99 others); Tue, 18 Feb 2020 08:36:15 -0500 Received: from 11.mo1.mail-out.ovh.net ([188.165.48.29]:40429 "EHLO 11.mo1.mail-out.ovh.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726340AbgBRNgP (ORCPT ); Tue, 18 Feb 2020 08:36:15 -0500 X-Greylist: delayed 1793 seconds by postgrey-1.27 at vger.kernel.org; Tue, 18 Feb 2020 08:36:13 EST Received: from player779.ha.ovh.net (unknown [10.108.42.174]) by mo1.mail-out.ovh.net (Postfix) with ESMTP id 28E691AFCCC for ; Tue, 18 Feb 2020 14:00:57 +0100 (CET) Received: from sk2.org (cre33-1_migr-88-122-126-116.fbx.proxad.net [88.122.126.116]) (Authenticated sender: steve@sk2.org) by player779.ha.ovh.net (Postfix) with ESMTPSA id 4B9ACF77764B; Tue, 18 Feb 2020 13:00:51 +0000 (UTC) From: Stephen Kitt To: Jonathan Corbet , Mauro Carvalho Chehab , linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Stephen Kitt Subject: [PATCH v2 7/8] docs: add a script to check sysctl docs Date: Tue, 18 Feb 2020 13:59:22 +0100 Message-Id: <20200218125923.685-8-steve@sk2.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200218125923.685-1-steve@sk2.org> References: <20200218125923.685-1-steve@sk2.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Ovh-Tracer-Id: 16143434340172320133 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedugedrjeekgdegjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpefuthgvphhhvghnucfmihhtthcuoehsthgvvhgvsehskhdvrdhorhhgqeenucfkpheptddrtddrtddrtddpkeekrdduvddvrdduvdeirdduudeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpqdhouhhtpdhhvghlohepphhlrgihvghrjeejledrhhgrrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehsthgvvhgvsehskhdvrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This script allows sysctl documentation to be checked against the kernel source code, to identify missing or obsolete entries. Running it against 5.5 shows for example that sysctl/kernel.rst has two obsolete entries and is missing 52 entries. Signed-off-by: Stephen Kitt --- Documentation/admin-guide/sysctl/kernel.rst | 3 + scripts/check-sysctl-docs | 181 ++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100755 scripts/check-sysctl-docs diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst index a67c218c4066..3d21e076aea4 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -2,6 +2,9 @@ Documentation for /proc/sys/kernel/ =================================== +.. See scripts/check-sysctl-docs to keep this up to date + + Copyright (c) 1998, 1999, Rik van Riel Copyright (c) 2009, Shen Feng diff --git a/scripts/check-sysctl-docs b/scripts/check-sysctl-docs new file mode 100755 index 000000000000..b3b47c188a2d --- /dev/null +++ b/scripts/check-sysctl-docs @@ -0,0 +1,181 @@ +#!/usr/bin/gawk -f +# SPDX-License-Identifier: GPL-2.0-only + +# Script to check sysctl documentation against source files +# +# Copyright © 2020 Stephen Kitt + +# Example invocation: +# scripts/check-sysctl-docs -vtable="kernel" \ +# Documentation/admin-guide/sysctl/kernel.rst \ +# $(git grep -l register_sysctl_table) +# +# 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: +# children: maps ctl_table names and procnames to child ctl_table names +# 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) +# files: maps procnames to source file names +# paths: maps ctl_path names to paths +# curpath: the name of the current ctl_path struct +# 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 children + delete entries + delete paths + curpath = "" + curtable = "" + curentry = "" + if (debug) print "Processing file " FILENAME +} + +/^static struct ctl_path/ { + match($0, /static struct ctl_path ([^][]+)/, tables) + curpath = tables[1] + if (debug) print "Processing path " curpath +} + +/^static struct ctl_table/ { + match($0, /static struct ctl_table ([^][]+)/, tables) + curtable = tables[1] + if (debug) print "Processing table " curtable +} + +/^};$/ { + curpath = "" + curtable = "" + curentry = "" +} + +curpath && /\.procname[\t ]*=[\t ]*".+"/ { + match($0, /.procname[\t ]*=[\t ]*"([^"]+)"/, names) + if (curentry) { + curentry = curentry "/" names[1] + } else { + curentry = names[1] + } + if (debug) print "Setting path " curpath " to " curentry + paths[curpath] = curentry +} + +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 +} + +/\.child[\t ]*=/ { + child = trimpunct($NF) + if (debug) print "Linking child " child " to table " curtable " entry " curentry + children[curtable][curentry] = child +} + +/register_sysctl_table\(.*\)/ { + match($0, /register_sysctl_table\(([^)]+)\)/, tables) + if (debug) print "Registering table " tables[1] + if (children[tables[1]][table]) { + for (entry in entries[children[tables[1]][table]]) { + printentry(entry) + } + } +} + +/register_sysctl_paths\(.*\)/ { + match($0, /register_sysctl_paths\(([^)]+), ([^)]+)\)/, tables) + if (debug) print "Attaching table " tables[2] " to path " tables[1] + if (paths[tables[1]] == table) { + for (entry in entries[tables[2]]) { + printentry(entry) + } + } + split(paths[tables[1]], components, "/") + if (length(components) > 1 && components[1] == table) { + # Count the first subdirectory as seen + seen[components[2]]++ + } +} + + +END { + for (entry in documented) { + if (!seen[entry]) { + print "No implementation for " entry + } + } +} -- 2.20.1