1142871Strhodes#!/bin/sh
2142871Strhodes#
3142871Strhodes# $FreeBSD$
4142871Strhodes#
5142871Strhodes#################################################################
6142871Strhodes# Missing Features:
7142871Strhodes# It would be nice to have OIDs separated into composite groups
8142871Strhodes# using the subsection mdoc(7) feature (.Ss) without adding extra
9142871Strhodes# files.
10142871Strhodes#
11142871Strhodes# The ability to notice when new OIDs are added to FreeBSD, and
12142871Strhodes# and the automation of their sorting and addition into the
13142871Strhodes# tunables.mdoc file.
14142871Strhodes#
15142871Strhodes# Perhaps a re-implementation in C?  This wouldn't be much of
16142871Strhodes# a challenge for the right individual but it may require a lot
17142871Strhodes# of changes to sysctl.h.  Eventually this utility should replace
18142871Strhodes# documenting sysctls in code and manual pages since this utility
19142871Strhodes# creates a manual page dynamicly based on the kernel.  This
20142871Strhodes# would kill duplication between manual pages and kernel code as
21142871Strhodes# well as improve the removal of sysctls when they are obsoleted.
22142871Strhodes#################################################################
23142871Strhodes
24142871Strhodes# Set our path up.
25142871StrhodesPATH=/bin:/usr/bin:/sbin:/usr/sbin
26142871Strhodes
27142871Strhodes# Set a unique date format in the produced manual page.
28142871StrhodesDATE=`LC_TIME=C date +"%B %d, %Y"`
29142871Strhodes
30142871Strhodes# We need a usage statement correct?
31142871StrhodesUSAGE="Usage: run.sh -k [absolute path]"
32142871Strhodes
33142871Strhodes# The endman function closes the list and adds the bottom
34142871Strhodes# part of our manual page.
35142871Strhodesendman() {
36142871Strhodescat <<EOF>> ./sysctl.5
37142871Strhodes.El
38142871Strhodes.Sh IMPLEMENTATION NOTES
39142871StrhodesThis manual page has been automatically generated by
40142871Strhodesa set of scripts written in
41142871Strhodes.Xr sh 1 .
42142871StrhodesThe
43142871Strhodes.Xr mdoc 7
44142871Strhodesmarkup is stored in the database file and extracted
45142871Strhodesaccordingly when invoked.
46142871StrhodesFor information on the
47142871Strhodes.Xr sysctl 8
48142871Strhodesimplementation, see the respecting manual pages.
49142871Strhodes.Sh SEE ALSO
50142871Strhodes.Xr loader.conf 5 ,
51142871Strhodes.Xr rc.conf 5 ,
52142871Strhodes.Xr sysctl.conf 5 ,
53142871Strhodes.Xr boot 8 ,
54142871Strhodes.Xr loader 8 ,
55142871Strhodes.Xr sysctl 8 ,
56142871Strhodes.Xr sysctl_add_oid 9 ,
57142871Strhodes.Xr sysctl_ctx_init 9
58142871Strhodes.Sh AUTHORS
59142871StrhodesThis manual page is automatically generated
60142871Strhodesby a set of scripts written by
61142871Strhodes.An -nosplit
62142871Strhodes.An Tom Rhodes Aq trhodes@FreeBSD.org ,
63142871Strhodeswith significant contributions from
64142871Strhodes.An Giorgos Keramidas Aq keramida@FreeBSD.org ,
65142871Strhodes.An Ruslan Ermilov Aq ru@FreeBSD.org ,
66142871Strhodesand
67142871Strhodes.An Marc Silver Aq marcs@draenor.org .
68142871Strhodes.Sh BUGS
69142871StrhodesSometimes
70142871Strhodes.Fx
71142871Strhodes.Nm sysctls
72142871Strhodescan be left undocumented by those who originally
73142871Strhodesimplemented them.
74142871StrhodesThis script was forged as a way to automatically
75142871Strhodesproduce a manual page to aid in the administration and
76142871Strhodesconfiguration of a
77142871Strhodes.Fx
78142871Strhodessystem.
79142871StrhodesIt also gets around adding a bunch of supporting code to the
80142871Strhodes.Nm
81142871Strhodesinterface.
82142871StrhodesEOF
83142871Strhodes}
84142871Strhodes
85142871Strhodes# The markup_create() function builds the actual
86142871Strhodes# markup file to be dropped into.  In essence,
87142871Strhodes# compare our list of tunables with the documented
88142871Strhodes# tunables in our tunables.mdoc file and generate
89142871Strhodes# the final 'inner circle' of our manual page.
90142871Strhodesmarkup_create() {
91142871Strhodes	sort  < _names |		\
92142871Strhodes	xargs -n 1 /bin/sh ./sysctl.sh  \
93142871Strhodes		> markup.file		\
94142871Strhodes		2> tunables.TODO
95142871Strhodes	rm _names
96142871Strhodes}
97142871Strhodes
98142871Strhodes# Finally, the following lines will call our functions and
99142871Strhodes# and create our document using the following function:
100142871Strhodespage_create() {
101142871Strhodes	startman
102142871Strhodes	/bin/cat ./markup.file >> sysctl.5
103142871Strhodes	endman
104142871Strhodes}
105142871Strhodes
106142871Strhodes# The startman function creates the initial mdoc(7) formatted
107142871Strhodes# manual page.  This is required before we populate it with
108142871Strhodes# tunables both loader and sysctl(8) oids.
109142871Strhodesstartman() {
110142871Strhodescat <<EOF>> ./sysctl.5
111142871Strhodes.\"
112142871Strhodes.\" Copyright (c) 2005 Tom Rhodes
113142871Strhodes.\" All rights reserved.
114142871Strhodes.\"
115142871Strhodes.\" Redistribution and use in source and binary forms, with or without
116142871Strhodes.\" modification, are permitted provided that the following conditions
117142871Strhodes.\" are met:
118142871Strhodes.\" 1. Redistribution of source code must retain the above copyright
119142871Strhodes.\"    notice, this list of conditions and the following disclaimer.
120142871Strhodes.\" 2. Redistribution's in binary form must reproduce the above copyright
121142871Strhodes.\"    notice, this list of conditions and the following disclaimer in the
122142871Strhodes.\"    documentation and/or other materials provided with the distribution.
123142871Strhodes.\"
124142871Strhodes.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
125142871Strhodes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
126142871Strhodes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
127142871Strhodes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
128142871Strhodes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
129142871Strhodes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
130142871Strhodes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
131142871Strhodes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
132142871Strhodes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
133142871Strhodes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
134142871Strhodes.\" SUCH DAMAGE.
135142871Strhodes.\"
136142871Strhodes.\"
137142871Strhodes.Dd $DATE
138142871Strhodes.Dt SYSCTL 5
139142871Strhodes.Os
140142871Strhodes.Sh NAME
141142871Strhodes.Nm sysctl
142142871Strhodes.Nd "list of available syctls based on kernel configuration"
143142871Strhodes.Sh DESCRIPTION
144142871Strhodes.Fx
145142871Strhodessupports kernel alterations on the fly or at
146142871Strhodessystem initialization by using a feature
147142871Strhodesknown as a
148142871Strhodes.Nm
149142871Strhodesand a database.
150142871StrhodesMany values may be altered simply by using the
151142871Strhodes.Xr sysctl 8
152142871Strhodesutility followed by a
153142871Strhodes.Nm
154142871Strhodesand its new value at the command prompt.
155142871StrhodesFor example:
156142871Strhodes.Dl sysctl kern.ipc.zero_copy.receive=1
157142871Strhodeswill enable zero copy sockets for receive.
158142871Strhodes.Pp
159142871StrhodesMany variables may only be available if specific kernel
160142871Strhodesoptions are built into the kernel.
161142871StrhodesFor example, the previous
162142871Strhodes.Nm
163142871Strhodesrequires
164142871Strhodes.Xr zero_copy 9 .
165142871Strhodes.Pp
166142871StrhodesMost of these values only offer an enable/disable
167142871Strhodesoption, altered by using a numerical value of
168142871Strhodes.Dq 0
169142871Strhodesor
170142871Strhodes.Dq 1
171142871Strhodeswhere the former is disable and latter is enable.
172142871StrhodesOther cases the
173142871Strhodes.Nm
174142871Strhodesmay require a string value.
175142871StrhodesThe
176142871Strhodes.Xr sysctl 8
177142871Strhodesutility may be used to dump a list of current
178142871Strhodesvalues which should provide an example of
179142871Strhodesthe non-numeric cases.
180142871Strhodes.Pp
181142871StrhodesIn cases where the value may not be altered, the
182142871Strhodesfollowing warning will be issued:
183142871Strhodes.Dq read only value
184142871Strhodesand the
185142871Strhodes.Nm
186142871Strhodeswill not be changed.
187142871StrhodesTo alter these values, the administrator may place
188142871Strhodesthem in the
189142871Strhodes.Xr sysctl.conf 5
190142871Strhodesfile.
191142871StrhodesThis will invoke the changes during
192142871Strhodessystem initialization for those values
193142871Strhodeswhich may be altered.
194142871StrhodesIn other cases, the
195142871Strhodes.Xr loader.conf 5
196142871Strhodesmay be used.
197142871StrhodesThen again, some of these
198142871Strhodes.Nm sysctls
199142871Strhodesmay never be altered.
200142871Strhodes.Pp
201142871StrhodesThe
202142871Strhodes.Nm
203142871Strhodessupported by
204142871Strhodes.Xr sysctl 8
205142871Strhodesare:
206142871Strhodes.Pp
207142871Strhodes.Bl -ohang -offset indent
208142871StrhodesEOF
209142871Strhodes}
210142871Strhodes
211142871Strhodes#
212142871Strhodes# The nm(1) utility must only be used on the architecture which
213142871Strhodes# we build it for.  Although i386 and pc98 are so; my only fear
214142871Strhodes# with this is that this will not work properly on cross-builds.
215142871Strhodes
216142871Strhodeswhile getopts k FLAG;
217142871Strhodes  do
218142871Strhodes    case "$FLAG" in
219142871Strhodes
220142871Strhodes	k)  LOCATION="$OPTARG" ;;
221142871Strhodes
222142871Strhodes	*)  echo "$USAGE"
223142871Strhodes	    exit 0 ;;
224142871Strhodes
225142871Strhodes  esac
226142871Strhodesdone
227142871Strhodes
228142871Strhodes# The k flag
229142871Strhodesshift
230142871Strhodes
231142871Strhodesif [ -z "$1" ] && [ -z "$LOCATION" ] ;
232142871Strhodes  then echo "Malformed or improper path specified";
233142871Strhodes  exit 1;
234142871Strhodesfi
235142871Strhodes
236142871Strhodesif [ -z "$LOCATION" ] ;
237142871Strhodes  then LOCATION="$1" \
238142871Strhodes    && for x in `find $LOCATION -name '*.kld'`  \
239142871Strhodes	$LOCATION/kernel;			\
240142871Strhodes	do nm $x |				\
241142871Strhodes	grep ' sysctl___' | uniq |		\
242142871Strhodes	sed 's/sysctl___//g' | sed 's/_/./g' |	\
243142871Strhodes	awk {'print $3'} > _names;
244142871Strhodes	done;
245142871Strhodes	markup_create
246142871Strhodes	page_create
247142871Strhodesfi
248