History log of /freebsd-current/sbin/sysctl/sysctl.c
Revision Date Author Comments
# 2e8ad2b6 30-Dec-2023 Hao-Yu Hou <howard.hou.fan@elsa.cs.nthu.edu.tw>

sysctl(8): Fix typo in comment

Line214: combind -> combine

Reviewed by: zlai
Event: Advanced UNIX Programming Course (Fall’23) at NTHU
Request: https://github.com/freebsd/freebsd-src/pull/966


# 32e86a82 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

sbin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 75be7e30 06-Oct-2023 Ed Maste <emaste@FreeBSD.org>

sysctl: emit a newline after NULL node descriptions

Previously when printing the sysctl description (via the -d flag) we
omitted the newline if the node provided no description (i.e., NULL).
This could be observed via e.g. `sysctl -d dev`.

PR: 44034
Reviewed by: zlei
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D42112


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# f126d349 24-Dec-2022 Kirk McKusick <mckusick@FreeBSD.org>

Add -F option to sysctl(8) to display sysctl format.

Also add a test to ensure that it is working correctly.

Submitted by: ota_j.email.ne.jp
Reviewed by: mckusick
Differential Revision: https://reviews.freebsd.org/D34012


# 4de76195 05-Dec-2021 Warner Losh <imp@FreeBSD.org>

sysctl: Small style fix

Slightly reorder to make this look better. No functional change.

Sponsored by: Netflix


# f1957db4 01-May-2021 Andrew Turner <andrew@FreeBSD.org>

Fix building sysctl(8) after c78ad20

In sysctl we parse an efi header on amd64. Fix this after changing the
virtual memory type from a void * to a uint64_t in c78ad20.


# 65efb73f 27-Jan-2021 Ryan Moeller <freqlabs@FreeBSD.org>

sbin/sysctl: Fix CTLFLAG_SKIP for adjacent nodes

The OID is saved when we encounter CTLFLAG_SKIP so that descendants can
be skipped as well. We then must not update the skip OID until we are
out of the node. This was achieved by resetting the skip OID once the
prefix no longer matches, but the case where the OID we reset on has
CTLFLAG_SKIP was not accounted for.

Reported by: mav
Reviewed by: mav
MFC after: 2 days
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D28364


# 401f82df 22-Dec-2020 Ryan Moeller <freqlabs@FreeBSD.org>

sbin/sysctl: Style fix

Remove parameter names from function prototype to match other
prototypes in the file.

Sponsored by: iXsystems, Inc.


# a5ec1dd4 22-Dec-2020 Ryan Moeller <freqlabs@FreeBSD.org>

sbin/sysctl: Always honor skip in sysctl_all

Fix broken CTLFLAG_SKIP when present on the first child of the requested
node.

We don't need to ignore skip for the first node because in sysctl_all()
we've implicitly visited the first node already when oid is specified.
The first call to show_var() in here is after we have iterated to the
next node. When the command line specifically requests a non-node sysctl
we go straight into show_var() without calling sysctl_all().

Reported by: jhb
Reviewed by: jhb
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D27674


# b64b636d 30-Oct-2020 John Baldwin <jhb@FreeBSD.org>

Use a dynamic buffer for the copy of a node's new value.

This permits setting a node's value to a string longer than BUFSIZ.

Reported by: Sony Arpita Das @ Chelsio
Reviewed by: freqlabs
MFC after: 1 week
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D27027


# e58483c4 24-Oct-2020 Ryan Moeller <freqlabs@FreeBSD.org>

sysctl+kern_sysctl: Honor SKIP for descendant nodes

Ensure we also skip descendants of SKIP nodes when iterating through children
of an explicitly specified node.

Reported by: np
Reviewed by: np
MFC after: 1 week
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D26833


# 8077b9bc 24-Oct-2020 Ryan Moeller <freqlabs@FreeBSD.org>

sysctl: Misc code cleanup

* Use defined SYS_SYSCTL names
* Use memcmp instead of explicit loop
* Use NULL instead of 0 for pointer value
* Use __FBSDID
* Reformat, improve comments in parse()

No functional changes.

Reviewed by: imp
MFC after: 1 week
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D26832


# 92e17803 05-Oct-2020 Ryan Moeller <freqlabs@FreeBSD.org>

Enable iterating all sysctls, even ones with CTLFLAG_SKIP

Add an "nextnoskip" sysctl that allows for listing of sysctls intended to be
normally skipped for cost reasons.

This makes it so the names/descriptions of those sysctls can be discovered with
sysctl -aN/sysctl -ad/sysctl -at.

It also makes it so children are visited when a node flagged with CTLFLAG_SKIP
is explicitly requested.

The intended use case is to mark the root "kstat" node with CTLFLAG_SKIP so that
the extensive and expensive stats are skipped by default but may still be easily
obtained without having to know them all (which may not even be possible) and
request each one-by-one.

Reviewed by: jhb
MFC after: 2 weeks
Relnotes: yes
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D26560


# a0efcf64 02-Sep-2020 Mark Johnston <markj@FreeBSD.org>

Add sysctl(8) formatting for hw.pagesizes.

- Change the type of hw.pagesizes to OPAQUE, since it returns an array.
- Modify the handler to only truncate the returned length if the caller
supplied an output buffer. This allows use of the trick of passing a
NULL output buffer to fetch the output size, while preserving
compatibility if MAXPAGESIZES is increased.
- Add a "S,pagesize" formatter to sysctl(8).

Reviewed by: alc, kib
MFC after: 2 weeks
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D26239


# f99e7b1a 24-Feb-2019 Vladimir Kondratyev <wulf@FreeBSD.org>

evdev: export event device properties through sysctl interface

A big security advantage of Wayland is not allowing applications to read
input devices all the time. Having /dev/input/* accessible to the user
account subverts this advantage.

libudev-devd was opening the evdev devices to detect their types (mouse,
keyboard, touchpad, etc). This don't work if /dev/input/* is inaccessible.
With the kernel exposing this information as sysctls (kern.evdev.input.*),
we can work w/o /dev/input/* access, preserving the Wayland security model.

Submitted by: Greg V <greg@unrelenting.technology>
Reviewed by: wulf, imp
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D18694


# 7404ab5b 08-Sep-2018 Konstantin Belousov <kib@FreeBSD.org>

Improve handling of the EFI map types[] array.

Use nitems(), do not assume EFI_MD_TYPE_ contiguous allocation, in
particular, switch to use designated array initializers.

Reviewed by: jhb (previous version)
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Approved by: re (gjb)


# d4bdf8ed 07-Sep-2018 Konstantin Belousov <kib@FreeBSD.org>

Teach sysctl(8) about the Persistent memory type.

Add PersistentMemory to the list of sysctl's known memory types
when decoding an EFI memory map.

Submitted by: D Scott Phillips <d.scott.phillips@intel.com>
MFC after: 1 week
Approved by: re (rgrimes)


# e1372c0e 07-Sep-2018 Konstantin Belousov <kib@FreeBSD.org>

Trim whitespace.

Approved by: re (gjb)


# 2365fe56 09-Mar-2018 John Baldwin <jhb@FreeBSD.org>

Permit sysctl(8) to set an array of numeric values for a single node.

Most sysctl nodes only return a single value, but some nodes return an
array of values (e.g. kern.cp_time). sysctl(8) understand how to display
the values of a node that returns multiple values (it prints out each
numeric value separated by spaces). However, until now sysctl(8) has
only been able to set sysctl nodes to a single value. This change
allows sysctl to accept a new value for a numeric sysctl node that contains
multiple values separated by either spaces or commas. sysctl(8) parses
this list into an array of values and passes the array as the "new" value
to sysctl(2).

Reviewed by: rpokala
MFC after: 1 week
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D14569


# 41c0f8d3 26-Nov-2017 Konstantin Belousov <kib@FreeBSD.org>

Improve sysctl(8) pretty printing of some structures.

S_vmtotal:
Use unsigned format to print unsigned memory counters from struct
vmtotal.
Remove unneeded cast, style locals declarations.

S_efi_map:
Make printing of the memory regions descriptions less MD by
using uintmax_t formats.

Noted by and discussed with: bde
Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# a18f34fe 31-Jul-2017 Andrew Gallatin <gallatin@FreeBSD.org>

Don't request CTLTYPE_OPAQUE if we can't print them.

The intent is to skip expensive opaque sysctls like tcp_pcblist unless
they are explicitly requested. Sysctl nodes like this don't show up in
sysctl -a, but they do generate output that winds up being dropped,
unless the user specifically requested binary/hex output or opaques.

This reduces the runtime of sysctl in many circumstances on a loaded
system. It also reduces the likelihood that simply gathering
diagnostics on a sick machine (stuck lock, etc) via sysctl -a might
push it over the edge into a total lockup.

Reviewed by: jtl
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D11461


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# 3ddb14a5 30-Dec-2016 Andriy Voskoboinyk <avos@FreeBSD.org>

sysctl(8): fix typename for uint32_t.

MFC after: 5 days.


# 944e0bab 18-Sep-2016 Konstantin Belousov <kib@FreeBSD.org>

Consolidate four efi_next_descriptor() definitions.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# 4dad99bf 24-Jun-2016 Alan Somers <asomers@FreeBSD.org>

Fix "sysctl vm.vmtotal" output on machines with > 2TB virtual memory

sbin/sysctl/sysctl.c
Fix integer overflows in printf format strings

PR: 199673
Submitted by: Vitaly Magerya
Reviewed by: cem
Approved by: re (marius)
MFC after: 4 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D6941


# 8020192d 09-Dec-2015 Marcelo Araujo <araujo@FreeBSD.org>

Add -t option to display field types.

PR: bin/203918
Submitted by: ota <ota@j.email.ne.jp>
Reviewed by: cem
Approved by: bapt (mentor)
Differential Revision: https://reviews.freebsd.org/D4451


# 2a71f1ed 06-Nov-2015 Conrad Meyer <cem@FreeBSD.org>

Follow-up to r290475: Add sysctl(8) support for added types

Sponsored by: EMC / Isilon Storage Division


# ec9f6de7 23-Oct-2015 Conrad Meyer <cem@FreeBSD.org>

sysctl(8): Fix style nits

Suggested by: bde
Sponsored by: EMC / Isilon Storage Division


# c3220d0b 22-Oct-2015 Conrad Meyer <cem@FreeBSD.org>

Sysctl: Add common support for U8, U16 types

Sponsored by: EMC / Isilon Storage Division


# e1619d12 07-Oct-2015 Baptiste Daroussin <bapt@FreeBSD.org>

Only print the errno string in case sysctl(3) does not file with ENOENT
This reduces the noise in error reporing from sysctl(8):

Before:
$ sysctl bla=something
sysctl: unknown oid 'bla': No such file or directory

After:
$ sysctl bla=something
sysctl: unknown oid 'bla'

MFC after: 1 week
Sponsored by: Gandi.net


# ca587fda 07-Oct-2015 Baptiste Daroussin <bapt@FreeBSD.org>

Trim spaces at the end of the buffer before trying to convert it to an oid

This allows to write entries in sysctl.conf with spaces before the '=' like
kern.ipc.shmmax = 9663676416

MFC after: 1 week
Sponsored by: Gandi.net


# aa255ef6 28-Jul-2015 Warner Losh <imp@FreeBSD.org>

Teach sysctl about the new optional suffix after IK to specify
precision. Update input as well. Add IK to the manual (it was missing
completely).

Differential Revision: https://reviews.freebsd.org/D3181


# 75820005 12-Feb-2015 John-Mark Gurney <jmg@FreeBSD.org>

add support for specifying an initial buffer size when fetching a
sysctl... This is useful for kern.arandom which (without -B) will
happily return 0 bytes, which isn't too useful or random...

fix spelling (thanks igor!) of settable while I'm here...


# 689c8e8b 01-Dec-2014 Xin LI <delphij@FreeBSD.org>

Fix inverted logic introduced in r272154.

Noticed by: trasz
MFC after: 2 weeks


# e267e00e 25-Sep-2014 Xin LI <delphij@FreeBSD.org>

Refactor the code a little bit to reduce duplicated code.

Reviewed by: mjg
MFC after: 2 weeks


# 4b8740cd 25-Sep-2014 Xin LI <delphij@FreeBSD.org>

Explicitly set errno to 0 before calling strto*.

Suggested by: mjg
MFC after: 2 weeks


# 9e4ed372 25-Sep-2014 Xin LI <delphij@FreeBSD.org>

The strtol(3) family of functions would set errno when it hits one.
Check errno and handle it as invalid input.

Obtained from: HardenedBSD
Submitted by: David CARLIER <devnexen@gmail.com>
MFC after: 2 weeks


# c58f8df6 23-Sep-2014 Xin LI <delphij@FreeBSD.org>

Constify a parameter of name2oid. No functional change.

MFC after: 2 months


# 7d8312cc 12-Sep-2014 John Baldwin <jhb@FreeBSD.org>

Add a sysctl to export the EFI memory map along with a handler in the
sysctl(8) binary to format it.

Reviewed by: emaste
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D771


# 59101c5d 12-Sep-2014 John Baldwin <jhb@FreeBSD.org>

Pass the length of an structure to the pretty-printer backends as a
size_t instead of an int.


# 89871cde 29-Aug-2014 John Baldwin <jhb@FreeBSD.org>

- Add a new structure type for the ACPI 3.0 SMAP entry that includes the
optional attributes field.
- Add a 'machdep.smap' sysctl that exports the SMAP table of the running
system as an array of the ACPI 3.0 structure. (On older systems, the
attributes are given a value of zero.) Note that the sysctl only
exports the SMAP table if it is available via the metadata passed from
the loader to the kernel. If an SMAP is not available, an empty array
is returned.
- Add a format handler for the ACPI 3.0 SMAP structure to the sysctl(8)
binary to format the SMAP structures in a readable format similar to
the format found in boot messages.

MFC after: 2 weeks


# 04006eab 27-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Don't hide zero-length strings when doing sysctl listings.

MFC after: 1 week


# c6919e7f 26-Nov-2013 Edward Tomasz Napierala <trasz@FreeBSD.org>

Fix warnings to not append "No error: 0".

MFC after: 1 month
Sponsored by: The FreeBSD Foundation


# 6f361351 12-Jan-2013 Xin LI <delphij@FreeBSD.org>

Use the right format string for line buffer.

PR: bin/174910
Submitted by: Fabian Keil <fk fabiankeil.de>


# da178c77 13-Dec-2012 Xin LI <delphij@FreeBSD.org>

Teach sysctl(8) about parsing a file (while I'm there also give it
capability of parsing both = and : formats).

Submitted by: hrs (initial version, bugs are mine)
MFC after: 3 months


# 403c7f59 11-Dec-2012 Alfred Perlstein <alfred@FreeBSD.org>

Make Tflag and Wflag filters work for more sysctl options.

To do this move the Tflag and Wflag checks earlier in show_var() so
we bail earlier for variables not matching our query.


# 9ecd2e32 10-Dec-2012 Alfred Perlstein <alfred@FreeBSD.org>

Allow sysctl to filter boot and runtime tunables.

Add the following flags to sysctl:
-W - show only writable sysctls
-T - show only tuneable sysctls

This can be used to create a /var/run/sysctl.boot to
compare set tunables versus booted tunables.

Sponsored by: iXsystems


# aae75101 10-Dec-2012 Xin LI <delphij@FreeBSD.org>

In parse():

- Only operate on copy, don't operate on source.
- Eliminate home-rolled strsep().
- Constify the parameter.

MFC after: 2 weeks


# ad0e6cda 11-Apr-2012 Eitan Adler <eadler@FreeBSD.org>

s/Free Memory Pages/Free Memory/ to avoid confusion, since we're
reporting a number of bytes rather than a number of pages

PR: misc/165208
Submitted by: Arnaud Lacombe <lacombar@gmail.com>
Approved by: cperciva
MFC after: 3 days


# 0b6230f1 01-Dec-2011 John Baldwin <jhb@FreeBSD.org>

If the -d flag is specified, ignore any new values specified and only
display the descriptions of specified nodes.

Reported by: Jason Hellenthal jhell of dataix net
MFC after: 2 weeks


# cbc134ad 19-Jan-2011 Matthew D Fleming <mdf@FreeBSD.org>

Introduce signed and unsigned version of CTLTYPE_QUAD, renaming
existing uses. Rename sysctl_handle_quad() to sysctl_handle_64().


# f8e4b4ef 19-Jan-2011 Matthew D Fleming <mdf@FreeBSD.org>

sysctl(8) should use the CTLTYPE to determine the type of data when
reading. (This was already done for writing to a sysctl). This
requires all SYSCTL setups to specify a type. Most of them are now
checked at compile-time.

Remove SYSCTL_*X* sysctl additions as the print being in hex should be
controlled by the -x flag to sysctl(8).

Succested by: bde


# 5bf6a940 17-Jan-2011 Matthew D Fleming <mdf@FreeBSD.org>

The kernel is not exporting any "T,dev_t" sysctl nodes anymore, so
remove the capability and mention from sysctl(8).


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 13e86ef7 16-Sep-2010 Marko Zec <zec@FreeBSD.org>

Make the format of "Real Memory" and "Virtual Memory" lines more
consistent with the rest of sysctl vm.vmtotal output.

MFC after: 3 days


# accfa147 20-Apr-2010 Rebecca Cran <brucec@FreeBSD.org>

MFC r205118:

Free the memory allocated via strdup.

PR: bin/113881
Submitted by: Alexander Drozdov (dzal_mail at mtu-net.ru)
Approved by: rrs (mentor)


# f2359a24 13-Mar-2010 Rebecca Cran <brucec@FreeBSD.org>

Free the memory allocated via strdup.

PR: bin/113881
Submitted by: Alexander Drozdov dzal_mail mtu-net.ru
Approved by: rrs (mentor)
MFC after: 1 week


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 6d7a8f6c 15-Feb-2010 Ulrich Spörlein <uqs@FreeBSD.org>

sysctl(8): make WARNS=3 clean

Fixes inspired by work done in DragonflyBSD.

PR: bin/140016
Approved by: ed (Co-mentor)


# a83e6639 14-Feb-2010 Gavin Atkinson <gavin@FreeBSD.org>

Merge r203310,203547,203717 from head:

Implement the "-i" option to sysctl(8), to ignore failures while
retrieving individual OIDs. This allows the same list of OIDs to be
passed to sysctl(8) across different systems where particular OIDs may
not exist, and still get as much information as possible from them.

PR: bin/123644
Submitted by: dhw


# aea5fda5 09-Feb-2010 Gavin Atkinson <gavin@FreeBSD.org>

Add -i to usage()

Noticed by: ru
MFC after: 5 days


# 24b2aa32 31-Jan-2010 Gavin Atkinson <gavin@FreeBSD.org>

Implement the "-i" option to sysctl(8), to ignore failures while
retrieving individual OIDs. This allows the same list of OIDs to be
passed to sysctl(8) across different systems where particular OIDs may not
exist, and still get as much information as possible from them.

PR: bin/123644
Submitted by: dhw
Approved by: ed (mentor)
MFC after: 2 weeks


# 8f1c21a6 03-Nov-2009 Ed Schouten <ed@FreeBSD.org>

Just use devname(3) to print device names.

Right now sysctl just prints the major/minor numbers of a device.
Instead of rolling our own routine for this, we'd better just call
devname(3) to perform a translation to a device name for us.


# a7b5ad27 21-Oct-2009 Ed Schouten <ed@FreeBSD.org>

Make input parsing in Farhenheit actually work.

Don't clobber *p with '\0' when testing whether it has the value of 'F'.
Just use the semantics of strtof() properly. If it returns p, we know
that it parsed the string until it reached 'C' or 'F'.

The code has not changed since it has been imported (r161951, Sep 3,
2006).

Submitted by: Alexandre Perrin <kaworu@kaworu.ch>
MFC after: 1 week


# db87e2dc 23-Jun-2009 John Hay <jhay@FreeBSD.org>

time_t does not always fit into long, for instance on arm. So rather cast
it intmax_t and use %j in printf.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# d9fcd86c 23-Jun-2008 Mike Makonnen <mtm@FreeBSD.org>

The sysctl(8) program exits on some errors and only emits warnings on
others. In the case where it displayed warnings it would still return
succesfully. Modify it so that it returns the number of sysctls that
it was not able to set.

Make use of this in rc.d to display only *unsuccessfull* attempts to
set sysctls.


# 9f05d312 15-Oct-2007 Alexander Leidinger <netchild@FreeBSD.org>

Backout sensors framework.

Requested by: phk
Discussed on: cvs-all


# 99f6b270 14-Oct-2007 Alexander Leidinger <netchild@FreeBSD.org>

Import OpenBSD's sysctl hardware sensors framework.

This commit includes the following core components:

* sample configuration file for sensorsd
* rc(8) script and glue code for sensorsd(8)
* sysctl(3) doc fixes for CTL_HW tree
* sysctl(3) documentation for hardware sensors
* sysctl(8) documentation for hardware sensors
* support for the sensor structure for sysctl(8)
* rc.conf(5) documentation for starting sensorsd(8)
* sensor_attach(9) et al documentation
* /sys/kern/kern_sensors.c
o sensor_attach(9) API for drivers to register ksensors
o sensor_task_register(9) API for the update task
o sysctl(3) glue code
o hw.sensors shadow tree for sysctl(8) internal magic
* <sys/sensors.h>
* HW_SENSORS definition for <sys/sysctl.h>
* sensors display for systat(1), including documentation
* sensorsd(8) and all applicable documentation

The userland part of the framework is entirely source-code
compatible with OpenBSD 4.1, 4.2 and -current as of today.

All sensor readings can be viewed with `sysctl hw.sensors`,
monitored in semi-realtime with `systat -sensors` and also
logged with `sensorsd`.

Submitted by: Constantine A. Murenin <cnst@FreeBSD.org>
Sponsored by: Google Summer of Code 2007 (GSoC2007/cnst-sensors)
Mentored by: syrinx
Tested by: many
OKed by: kensmith
Obtained from: OpenBSD (parts)


# 6b6b665b 11-Jun-2007 Bruce Evans <bde@FreeBSD.org>

When we return from a "show" function without printing anything except
a warning, return 1 instead of 0 to indicate that we didn't print
anything, so that top-level callers don't print a spurious newline.
This is mainly to fix output formatting when stderr is redirected. It
also helps in some cases when stderr is interleaved with stdout,
depending on the details of the interleaving (this program has the
usual null explicit support for syncing stderr with stdout).

Return 1 instead of -1 after printing the "malloc failed" warning, since
the return value is boolean.


# e37d2b30 10-Jun-2007 David Malone <dwmalone@FreeBSD.org>

Some improvements to the int-type printing code based on suggestions by bde.


# fd8c668a 10-Jun-2007 David Malone <dwmalone@FreeBSD.org>

Fix a number of WARNS, including printf, constness and unsigned comparison
warnings.


# 21e1f596 10-Jun-2007 David Malone <dwmalone@FreeBSD.org>

Some style improvements suggested by bde, including removing an
unused include, adding parens for return and sizeof and renaming,
adding some missing whitespace and sorting some variables.


# 41e419cb 04-Jun-2007 David Malone <dwmalone@FreeBSD.org>

Use common code for printing ints and longs by coppying the sysctl
value into a variable of the right type and then printing it via
an intmax_t. This makes avoids some duplication and makes it easy
to add a new integer format Q for printing things of type CTLTYPE_QUAD.


# f195a122 09-Dec-2006 Warner Losh <imp@FreeBSD.org>

Style: Shorten a couple of lines with u_int and u_long.


# bad4d172 27-Nov-2006 Ruslan Ermilov <ru@FreeBSD.org>

- Revert signedness type changes to "struct vmtotal"; by making
them unsigned I made the possible overflows hard to detect,
and it only saved 1 bit which isn't principal, even less now
that the underlying issue with the total of virtual memory has
been fixed. (For the record, it will overflow with >=2T of
VM total, with 32-bit ints used to keep counters in pages.)

- While here, fix printing of other "struct vmtotal" members
such as t_rq, t_dw, t_pw, and t_sw as they are also signed.

Reviewed by: bde
MFC after: 3 days


# 20739dfa 23-Nov-2006 Ruslan Ermilov <ru@FreeBSD.org>

Fix the format specifier suitable for uintmax_t.


# 5c88a11e 20-Nov-2006 Ruslan Ermilov <ru@FreeBSD.org>

- Fix types of "struct vmmeter" members so they are unsigned.

- Fix overflow bugs in sysctl(8), systat(1), and vmstat(8)
when printing values of "struct vmmeter" in kilobytes as
they don't necessarily fit into 32 bits. (Fix sysctl(8)
reporting of a total virtual memory; it's in pages too.)


# d566310d 12-Oct-2006 Hartmut Brandt <harti@FreeBSD.org>

Remove a debugging statement from the previous commit.


# 48cd487a 12-Oct-2006 Hartmut Brandt <harti@FreeBSD.org>

Don't free the buffer with the sysctl value before printing it.


# ccf25977 06-Sep-2006 Ruslan Ermilov <ru@FreeBSD.org>

While convenient, avoid using alloca() for reasons specified in
the BUGS section of the alloca(3) manpage. In particular, when
the number of TCP sockets is several tens of thousand, trying to
"sysctl -a" would SIGSEGV on the net.inet.tcp.pcblist entry (it
would exceed the stacksize ulimit, in an undetectable manner).

Reported by: Igor Sysoev


# d45564dc 03-Sep-2006 Hajimu UMEMOTO <ume@FreeBSD.org>

Support Celsius (nn.nC), Fahrenheit (nn.nF) and Kelvin (nnnn) to
specify temperature.

Reviewed by: njl
MFC after: 3 days


# e556ec91 15-Aug-2006 Ruslan Ermilov <ru@FreeBSD.org>

Fix printing of integer Kelvins broken in rev. 1.71, which is
fatal on sizeof(int) != sizeof(long) systems (such as amd64).

MFC after: 1 day


# c157a036 12-Aug-2006 David E. O'Brien <obrien@FreeBSD.org>

Add an extension to the UINT & ULONG types. The XINT & XLONG types behave
the same, except sysctl(8) will print out the values in hex.


# 091eb5a3 04-Aug-2006 Nate Lawson <njl@FreeBSD.org>

Use floating point instead of hacking something together. Suggested by
bde@. Fix nearby int conversion and a couple style bugs.

MFC after: 1 day


# e05cdb74 24-Jul-2006 Nate Lawson <njl@FreeBSD.org>

Fix printing of negative decimal values in Kelvin to Celsius conversion.

MFC after: 3 days


# 855b068a 01-Dec-2005 Ruslan Ermilov <ru@FreeBSD.org>

Add -q to usage().


# f93d36fd 15-Sep-2005 Robert Watson <rwatson@FreeBSD.org>

Add "-q" argument to sysctl(8), which suppresses a limited set of warnings/
errors generated. In particular, it suppresses "unknown oid" when
attempting to get or set a sysctl not present in the kernel.

MFC after: 1 week


# b2680e20 13-Apr-2005 Matthew N. Dodd <mdodd@FreeBSD.org>

Show descriptions for type CTLTYPE_NODES.


# 9f98e452 13-Apr-2005 Matthew N. Dodd <mdodd@FreeBSD.org>

Zero buffers. Seatbelt against sysctl(3) returning non-NUL terminated
string data.


# 8d646af5 10-Feb-2005 Ruslan Ermilov <ru@FreeBSD.org>

Sync program's usage() with manpage's SYNOPSIS.


# 1d4961c0 25-Jan-2005 Suleiman Souhlal <ssouhlal@FreeBSD.org>

Get rid of a NULL dereference when oid is too long.

Reviewed by: keramida
Approved by: grehan (mentor)
MFC after: 1 week


# 0a16dedc 17-Sep-2004 Lukas Ertl <le@FreeBSD.org>

Use correct format string.

Submitted by: ssouhlal


# c591d41f 30-Aug-2004 Peter Wemm <peter@FreeBSD.org>

Add a suffix descriptor for the acpi thermal values as a hint for the userland
sysctl tool to print a more readable value for temperatures.


# 4c723140 09-Apr-2004 Mark Murray <markm@FreeBSD.org>

Remove advertising clause from University of California Regent's license,
per letter dated July 22, 1999.

Approved by: core, imp


# 4d90830f 01-Mar-2004 Dima Dorfman <dd@FreeBSD.org>

Add CTLTYPE_QUAD to the list of types for which we don't want an empty
value. All the other numeric types are doing it . . .


# 705916c6 07-Nov-2003 Dag-Erling Smørgrav <des@FreeBSD.org>

Whitespace cleanup.


# 45817aaa 07-Nov-2003 Dag-Erling Smørgrav <des@FreeBSD.org>

Add a command-line option to format output for human readability.
Currently, the only effect it has is to print some (but not all) numbers
using thousands separators.


# ac8711d2 01-Nov-2003 Mike Silbersack <silby@FreeBSD.org>

Fix a few style glitches in the previous commit and make the
tunable error message more brief.

Suggested by: bde


# 7e9c84c7 25-Oct-2003 Peter Wemm <peter@FreeBSD.org>

Fix a 64 bit warning. Have set_T_dev_t() take a pointer to a size_t rather
than a pointer to an int, since that is what it really wants anyway.


# d108e663 21-Oct-2003 Mike Silbersack <silby@FreeBSD.org>

Wrap a long line in the previous commit

Suggested by: njl


# 9b4b73b7 21-Oct-2003 Mike Silbersack <silby@FreeBSD.org>

Have sysctl print out a more useful error message when it detects that the
user has attempted to write to a read only, tunable value.


# a78d3eaf 15-Jun-2003 Robert Watson <rwatson@FreeBSD.org>

Tighten up the string->integer conversion in sysctl(8):

(1) Reject zero-length strings for CTLTYPE_INT, _UINT, _LONG,
_ULONG. Do not silently convert to 0.

(2) When converting CTLTYPE_INT, _UINT, _LONG, and _ULONG, check the
end pointer generated by strtol() and strtoul() rather than
discarding it. Reject the string if either none of the string
was useful for conversion to an integer, or if there was
trailing garbage.

I.e., we will not allow you to set a numeric sysctl to a value unless
we can completely convert the string argument to a numeric value.
I tripped over this when I put the following in /etc/sysctl.conf:

kern.maxfiles="4000"

Ouch.


# 5b03e4b6 03-Apr-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Output machdep.guessed_bootdev as an integer rather than try to format
it according to ancient and obsolete rules.

This removes one more user of <sys/diskslice.h>


# 661b2c16 21-Jan-2003 Peter Wemm <peter@FreeBSD.org>

Fix what I think is an off-by-one in certain worst-case scenarios
caused by rev 1.45. (eg: the estimate being exactly half of the result.)


# 654e22e7 11-Jan-2003 Matthew Dillon <dillon@FreeBSD.org>

Cleanup the formatting from the last commit, convert everything to
a more human-readable 'kilobytes' instead of pages.


# f7550ecf 11-Jan-2003 Matthew Dillon <dillon@FreeBSD.org>

Make 'sysctl vm.vmtotal' work properly using updated patch from Hiten.
(the patch in the PR was stale).

PR: kern/5689
Submitted by: Hiten Pandya <hiten@unixdaemons.com>


# 9866352e 12-Nov-2002 Peter Wemm <peter@FreeBSD.org>

Fix a "bug" in sysctl(8). Limit the length when we print a string from
the kernel rather than ignoring the length and keeping on going till we
finally hit a \0 character in the buffer.


# 7fed38d0 25-Aug-2002 Philippe Charnier <charnier@FreeBSD.org>

Replace various spelling with FALLTHROUGH which is lint()able


# 996076bb 24-May-2002 Alfred Perlstein <alfred@FreeBSD.org>

Don't err(3) (and exit prematurely) when a sysctl's object size has
changed, instead just warn(3)


# 76d3dc52 08-May-2002 Andrey A. Chernov <ache@FreeBSD.org>

Don't forget to null-terminate string we got from sysctl (f.e. in 'A' format).
Stack garbadge may be printed otherwise.


# b35c8f28 14-Apr-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Take the "tickadj" element out of struct clockinfo. Our adjtime(2)
implementation is being changed and the very concept of tickadj will
no longer be meaningful.


# bca9bbea 10-Mar-2002 Luigi Rizzo <luigi@FreeBSD.org>

Make the handling of machdep.guessed_bootdev compiled on i386 only.


# 60cf2c12 10-Mar-2002 Luigi Rizzo <luigi@FreeBSD.org>

Export a (machine dependent) kernel variable bootdev as
machdep.guessed_bootdev, and add code to sysctl to parse its value
and give a (not necessarily correct) name to the device we booted
from (the main motivation for this code is to use the info in the
PicoBSD boot scripts, and the impact on the kernel is minimal).

NOTE: the information available in bootdev is not always reliable,
so you should not trust it too much. The parsing code is the same
as in boot2.c, and cannot cover all cases -- as it is, it seems to
work fine with floppies and IDE disks recognised by the BIOS. It
_should_ work as well with SCSI disks recognised by the BIOS.
Booting from a CDROM in floppy emulation will return /dev/fd0 (because
this is what the BIOS tells us).
Booting off the network (e.g. with etherboot) leaves bootdev unset so
the value will be printed as "invalid (0xffffffff)".

Finally, this feature might go away at some point, hopefully when we
have a more reliable way to get the same information.

MFC-after: 5 days


# ce685842 24-Feb-2002 Bruce Evans <bde@FreeBSD.org>

#include <sys/time.h> instead of depending on namespace pollution in
<sys/stat.h> for its prerequisite <sys/time.h>.

#include <sys/param.h> in the correct place instead of bogusly including
<sys/types.h>.


# d58f0054 30-Dec-2001 Poul-Henning Kamp <phk@FreeBSD.org>

Allow setting of variables of type dev_t by indicating the name of
a special file on the command line, eg:
sysctl kern.dumpdev=/dev/ad1s1b

In parse(), when a value is given for a CTLTYPE_QUAD variable,
newval and newsize erroneously fail to be set because of an early
"break".

show_var() contains code that duplicates the functionality of the
oidfmt() function.

PR: 33151, 33150
Submitted by: Thomas Quinot <thomas@cuivre.fr.eu.org>


# 6105f815 15-Dec-2001 Luigi Rizzo <luigi@FreeBSD.org>

Add code to export and print the description associated to sysctl
variables. Use the -d flag in sysctl(8) to see this information.

Possible extensions to sysctl:
+ report variables that do not have a description
+ given a name, report the oid it maps to.

Note to developers: have a look at your code, there are a number of
variables which do not have a description.

Note to developers: do we want this in 4.5 ? It is a very small change
and very useful for documentation purposes.

Suggested by: Orion Hodson


# d0b8aabb 30-Oct-2001 Anton Berezin <tobez@FreeBSD.org>

Implement -e option. It modifies the output produced by sysctl(8) in
such a way that the name and the value of the variable(s) are separated
with `=' instead of the usual `: '. This is useful for producing output
that can be fed back to the sysctl utility (pasted to sysctl.conf, for
example).

Reviewed by: rwatson
Approved by: markm
MFC after: 2 weeks


# 1ce1a53d 18-Jun-2001 Jim Pirzyk <pirzyk@FreeBSD.org>

modfied sysctl command to allow setting values > 2GB if the mib supports it.

PR: kern/21132
Reviewed by: no objections to by -arch
MFC after: 1 month


# 31fb4661 08-Jun-2001 Dima Dorfman <dd@FreeBSD.org>

Normalize the use of sizeof according to style(9).

Reviewed by: md5(1)


# ce359783 31-May-2001 Dima Dorfman <dd@FreeBSD.org>

Remove unused variable (descr) in show_var().

PR: 22582
Submitted by: Giorgos Keramidas <charon@gray.westgate.gr>


# a89ab9bb 27-May-2001 Dag-Erling Smørgrav <des@FreeBSD.org>

Perform random drive-by style cleanups, and rewrite a while loop that
offended my artistic sensibilities.


# 9a2402bc 27-May-2001 Dag-Erling Smørgrav <des@FreeBSD.org>

Try to make sysctl options slightly more orthogonal:

- introduce a -o option that displays opaque variables.
- introduce a -x option that displays opaque variables in full.
- deprecate -A in favor of -ao and -X in favor of -ax.
- remove -A and -X from usage() and SYNOPSIS (but not from DESCRIPTION).
- ignore -a if one or more variables were listed on the command line.
- deprecate -w, it is not needed to determine the user's intentions.
- some language and style cleanup in the man page.

This commit should not break any existing scripts.

MFC after: 4 weeks


# 0ef56fd8 14-Jan-2001 Dag-Erling Smørgrav <des@FreeBSD.org>

Document the -N option in the usage message and the man page.


# ca5fac55 14-Jan-2001 Dag-Erling Smørgrav <des@FreeBSD.org>

Add a -N option that makes sysctl(8) print out just the variable names.
Zsh users can add the following to their .zshrc for sysctl completion:

function listsysctls {
case $1 in
*.*) set -A reply $(sysctl -AN ${1%.*}) ;;
*) set -A reply $(sysctl -AN) ;;
esac
}
compctl -K listsysctls sysctl

While I'm here, brucify the getopt() switch.


# 3c884b50 23-Oct-2000 Andrew Gallatin <gallatin@FreeBSD.org>

Give correct results for SYSCTL_LONG arrays when sizeof(int) != sizeof(long)
This fixes unaligned access on alpha for, eg, sysctl kern.ipc.mbtypes.


# aa02fb57 11-Jul-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Array of long support.

Submitted by: Ian Dowse <iedowse@maths.tcd.ie>


# 9701cd40 05-Jul-2000 John Baldwin <jhb@FreeBSD.org>

Support for unsigned integer and long sysctl variables. Update the
SYSCTL_LONG macro to be consistent with other integer sysctl variables
and require an initial value instead of assuming 0. Update several
sysctl variables to use the unsigned types.

PR: 15251
Submitted by: Kelly Yancey <kbyanc@posi.net>


# 6ed3a297 10-Jun-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Handle minors like ls(1) does it.

PR: 19179
Submitted by: Kelly Yancey <kbyanc@posi.net>


# 2d730c26 22-Nov-1999 Dag-Erling Smørgrav <des@FreeBSD.org>

Belatedly back out rev. 1.20.


# 26909c80 17-Nov-1999 Greg Lehey <grog@FreeBSD.org>

Allow octal or hex input.
Suggested-by: Geoff Steckel <gwes@sitaranetworks.com>


# 7f3dea24 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# c1160fe4 20-Jul-1999 Bill Fumerola <billf@FreeBSD.org>

Avoid ambigious if/else


# 81e7454a 09-Jan-1999 Dag-Erling Smørgrav <des@FreeBSD.org>

Clean up option handling a little.
Add an option for showing sysctl descriptions instead of their values.


# 2b4c0a3b 08-Nov-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Allow for printing out integer arrays.


# dbf9b92f 25-Aug-1998 Doug Rabson <dfr@FreeBSD.org>

Change length arguments to sysctl to size_t.


# c2deb608 29-Jun-1998 Bruce Evans <bde@FreeBSD.org>

Don't assume that time_t is long.


# 14b94d04 17-Nov-1997 John Polstra <jdp@FreeBSD.org>

Add missing argument detected by "-Wformat".


# d9b1bc77 19-Oct-1997 Philippe Charnier <charnier@FreeBSD.org>

Use err(3). Change err(-1,... to err(1,...


# 59fe2c14 02-Aug-1997 Bruce Evans <bde@FreeBSD.org>

Import Lite2's src/usr.sbin, except for timed. All changed files
except one unimportant one have already left the vendor branch.


# 0fad62ae 24-Jun-1997 John Hay <jhay@FreeBSD.org>

Display tickadj in struct clockinfo.


# 6c3f552a 30-Mar-1997 Warner Losh <imp@FreeBSD.org>

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# 476602a9 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 019d9330 09-Apr-1996 Sujal Patel <smpatel@FreeBSD.org>

Fix a core dump when the user gives "-w" without an "="


# 1d86b91c 20-Dec-1995 Poul-Henning Kamp <phk@FreeBSD.org>

The rewamped sysctl program that will find all the variables itself.
Also a couple of handy new options.


# 07f16e53 17-Nov-1995 Poul-Henning Kamp <phk@FreeBSD.org>

Make sysctl compile again by removing all the debug stuff.


# d3628763 11-Jun-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Merge RELENG_2_0_5 into HEAD


# 709e8f9a 29-May-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Remove trailing whitespace.


# 55678a2e 12-May-1995 Garrett Wollman <wollman@FreeBSD.org>

Learn how to print out kern.dumpdev as a name.


# 9426bb7c 15-Feb-1995 Garrett Wollman <wollman@FreeBSD.org>

Allow the user access to net.inet.igmp, even though there's nothing
sysctl(8) can interpret there. (Someday there might be.)


# 35c13fa0 09-Feb-1995 Garrett Wollman <wollman@FreeBSD.org>

Implement TCP MIB variables.


# ebe06549 08-Aug-1994 Garrett Wollman <wollman@FreeBSD.org>

Suppress irritating extra newline after kern.boottime.


# dea673e9 25-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite usr.sbin Sources