sysdoc.sh revision 307403
1#!/bin/sh
2#
3# $FreeBSD: stable/10/tools/tools/sysdoc/sysdoc.sh 307403 2016-10-16 22:02:50Z sevan $
4#
5#################################################################
6# Missing Features:
7# It would be nice to have OIDs separated into composite groups
8# using the subsection mdoc(7) feature (.Ss) without adding extra
9# files.
10#
11# The ability to notice when new OIDs are added to FreeBSD, and
12# and the automation of their sorting and addition into the
13# tunables.mdoc file.
14#
15# Perhaps a re-implementation in C?  This wouldn't be much of
16# a challenge for the right individual but it may require a lot
17# of changes to sysctl.h.  Eventually this utility should replace
18# documenting sysctls in code and manual pages since this utility
19# creates a manual page dynamicly based on the kernel.  This
20# would kill duplication between manual pages and kernel code as
21# well as improve the removal of sysctls when they are obsoleted.
22#################################################################
23
24# Set our path up.
25PATH=/bin:/usr/bin:/sbin:/usr/sbin
26
27# Set a unique date format in the produced manual page.
28DATE=`LC_TIME=C date +"%B %d, %Y"`
29
30# We need a usage statement correct?
31USAGE="Usage: run.sh -k [absolute path]"
32
33# The endman function closes the list and adds the bottom
34# part of our manual page.
35endman() {
36cat <<EOF>> ./sysctl.5
37.El
38.Sh IMPLEMENTATION NOTES
39This manual page has been automatically generated by
40a set of scripts written in
41.Xr sh 1 .
42The
43.Xr mdoc 7
44markup is stored in the database file and extracted
45accordingly when invoked.
46For information on the
47.Xr sysctl 8
48implementation, see the respecting manual pages.
49.Sh SEE ALSO
50.Xr loader.conf 5 ,
51.Xr rc.conf 5 ,
52.Xr sysctl.conf 5 ,
53.Xr boot 8 ,
54.Xr loader 8 ,
55.Xr sysctl 8 ,
56.Xr sysctl_add_oid 9 ,
57.Xr sysctl_ctx_init 9
58.Sh AUTHORS
59This manual page is automatically generated
60by a set of scripts written by
61.An -nosplit
62.An Tom Rhodes Aq Mt trhodes@FreeBSD.org ,
63with significant contributions from
64.An Giorgos Keramidas Aq Mt keramida@FreeBSD.org ,
65.An Ruslan Ermilov Aq Mt ru@FreeBSD.org ,
66and
67.An Marc Silver Aq Mt marcs@draenor.org .
68.Sh BUGS
69Sometimes
70.Fx
71.Nm sysctls
72can be left undocumented by those who originally
73implemented them.
74This script was forged as a way to automatically
75produce a manual page to aid in the administration and
76configuration of a
77.Fx
78system.
79It also gets around adding a bunch of supporting code to the
80.Nm
81interface.
82EOF
83}
84
85# The markup_create() function builds the actual
86# markup file to be dropped into.  In essence,
87# compare our list of tunables with the documented
88# tunables in our tunables.mdoc file and generate
89# the final 'inner circle' of our manual page.
90markup_create() {
91	sort -u  < _names |		\
92	xargs -n 1 /bin/sh ./sysctl.sh  \
93		> markup.file		\
94		2> tunables.TODO
95	rm _names
96}
97
98# Finally, the following lines will call our functions and
99# and create our document using the following function:
100page_create() {
101	startman
102	/bin/cat ./markup.file >> sysctl.5
103	endman
104}
105
106# The startman function creates the initial mdoc(7) formatted
107# manual page.  This is required before we populate it with
108# tunables both loader and sysctl(8) oids.
109startman() {
110cat <<EOF>> ./sysctl.5
111.\"
112.\" Copyright (c) 2005 Tom Rhodes
113.\" All rights reserved.
114.\"
115.\" Redistribution and use in source and binary forms, with or without
116.\" modification, are permitted provided that the following conditions
117.\" are met:
118.\" 1. Redistribution of source code must retain the above copyright
119.\"    notice, this list of conditions and the following disclaimer.
120.\" 2. Redistribution's in binary form must reproduce the above copyright
121.\"    notice, this list of conditions and the following disclaimer in the
122.\"    documentation and/or other materials provided with the distribution.
123.\"
124.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
125.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
126.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
127.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
128.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
129.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
130.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
131.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
132.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
133.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
134.\" SUCH DAMAGE.
135.\"
136.\"
137.Dd $DATE
138.Dt SYSCTL 5
139.Os
140.Sh NAME
141.Nm sysctl
142.Nd "list of available syctls based on kernel configuration"
143.Sh DESCRIPTION
144.Fx
145supports kernel alterations on the fly or at
146system initialization by using a feature
147known as a
148.Nm
149and a database.
150Many values may be altered simply by using the
151.Xr sysctl 8
152utility followed by a
153.Nm
154and its new value at the command prompt.
155For example:
156.Dl sysctl kern.ipc.zero_copy.receive=1
157will enable zero copy sockets for receive.
158.Pp
159Many variables may only be available if specific kernel
160options are built into the kernel.
161For example, the previous
162.Nm
163requires
164.Xr zero_copy 9 .
165.Pp
166Most of these values only offer an enable/disable
167option, altered by using a numerical value of
168.Dq 0
169or
170.Dq 1
171where the former is disable and latter is enable.
172Other cases the
173.Nm
174may require a string value.
175The
176.Xr sysctl 8
177utility may be used to dump a list of current
178values which should provide an example of
179the non-numeric cases.
180.Pp
181In cases where the value may not be altered, the
182following warning will be issued:
183.Dq read only value
184and the
185.Nm
186will not be changed.
187To alter these values, the administrator may place
188them in the
189.Xr sysctl.conf 5
190file.
191This will invoke the changes during
192system initialization for those values
193which may be altered.
194In other cases, the
195.Xr loader.conf 5
196may be used.
197Then again, some of these
198.Nm sysctls
199may never be altered.
200.Pp
201The
202.Nm
203supported by
204.Xr sysctl 8
205are:
206.Pp
207.Bl -ohang -offset indent
208EOF
209}
210
211#
212# The nm(1) utility must only be used on the architecture which
213# we build it for.  Although i386 and pc98 are so; my only fear
214# with this is that this will not work properly on cross-builds.
215
216while getopts k FLAG;
217  do
218    case "$FLAG" in
219
220	k)  LOCATION="$OPTARG" ;;
221
222	*)  echo "$USAGE"
223	    exit 0 ;;
224
225  esac
226done
227
228# The k flag
229shift
230
231if [ -z "$1" ] && [ -z "$LOCATION" ] ;
232  then echo "Malformed or improper path specified";
233  exit 1;
234fi
235
236if [ -z "$LOCATION" ] ;
237  then LOCATION="$1" \
238    && for x in `find $LOCATION -name '*.kld'`  \
239	$LOCATION/kernel;			\
240	do nm $x |				\
241	sed -n '/sysctl___/ {
242		's/[\.a-z_]*sysctl___//g'
243		's/_/./g'
244		p
245	}' |					\
246	awk {'print $3'} |			\
247	sort -u > _names;
248	done;
249	markup_create
250	page_create
251fi
252