nsysctl 2.0

Posted on March 9, 2021

nsysctl version 2.0 is out!

The nsysctl utility can get or set the state of the FreeBSD kernel at runtime. The system exposes the available parameters as objects of a “Management Information Base” (MIB), nsysctl can explore the MIB, print the properties of an object, get or set its value and show the output in human and machine readable formats.

To install the port sysutils/nsysctl:

# cd /usr/ports/sysutils/nsysctl/ && make install clean

To add the package:

# pkg install nsysctl

Features

usage: nsysctl [--libxo options [-r tagroot]] [-DdeFGgHIilnOpqTtvW]
               [-N | -h [b | o | x]] [-B bufsize] [-f filename] [-s sep]
               name[=value[,value]] ...
       nsysctl [--libxo options [-r tagroot]] [-DdeFGgHIklnOpqSTtvW]
               [-N | -Vh [b | o | x]] [-B bufsize] [-s sep] -a
  • get or set the system state at runtime,
  • handle an object up to CTL_MAXNAME levels,
  • print the right object also with an empty level name,
  • options to show the properties of a parameter,
  • output explicitly indicated by the options,
  • options not mutually exclusive,
  • output via libxo in human and machine readable formats,
  • isolated code to manage opaque values,
  • some string value is parsed to show structured output,
  • avoid non-primitive data types hardcode via libnv,
  • debug without kernel recompilation with SYSCTL_DEBUG.

Version 2.0 improvements

CHANGELOG 2.0

 * change: sysctl library sysctlmibinfo -> sysctlmibinfo2
 * delete: undocumented interface (kern/kern_sysctl.c) support
 * delete: sysctlinfo_helpers.h/c, use sysctlinfo via sysctlmibinfo2
 * improve: manual DESCRIPTION
 * add: libnv(9) Format
 * add: opt -k, print SKIP with -a
 * add: opt -H, print object handler "Defined/Undefined"
 * add: opaque S,pagesizes for hw.pagesizes
 * change: opt -pg [FLAGS] -> [FLAGS-RAW]
 * change: opt -g with xml <flags> -> <flags-raw>
 * change: opt -pG [TRUE-FLAGS] -> [FLAGS]
 * change: opt -G with xml <flags-true> -> <flags>
 * change: opt -m -> -S
 * fix: opt -S only with -a
 * change: opt -y -> -O
 * change: opt -pO [ID] -> [OID]
 * change: opt -O xml
	<id> <level1>X</level1> <level2>Y</level2> </id> ->
	<OID>X.Y</OID>
 * change: opt -e <sep> -> -s <sep>
 * add: opt -e, like sysctl
 * change: opt -pF [FORMAT-STRING] -> [FORMAT]
 * change: opt -v show value -> show version
 * change: show value by default like sysctl
 * change: opt -V with -a, show object with/without a value
 * add: opt -n hide name, like sysctl
 * change: -N show name -> hide value
 * change: show name by default like sysctl
 * delete: -A, in compatibility like sysctl
 * delete: -X, in compatibility like sysctl
 * change: opt -D = -dFGHlOt

Example 1: libnv and libnv+libxo

Example 2: Options to know useful info to handle objects

% nsysctl -dtFG -s ' - ' hw.snd.report_soft_formats
hw.snd.report_soft_formats - report software-emulated formats - integer - I -
RD WR RW MPSAFE - 1
% nsysctl -pdtFG -s ", " dev.cpu.0.temperature
[NAME]: dev.cpu.0.temperature, [DESCRIPTION]: Current temperature,
[TYPE]: integer, [FORMAT]: IK, [FLAGS]: RD DYN MPSAFE, [VALUE]: 46.950006C
% nsysctl -pDg -s ', ' kern.ostype
[OID]: 1.1, [NAME]: kern.ostype, [LABEL]: , [DESCRIPTION]: Operating system
type, [TYPE]: string, [FORMAT]: A, [FLAGS-RAW]: 2147778560, [FLAGS]: RD MPSAFE
CAPRD, [HANDLER]: Defined, [VALUE]: FreeBSD

Example 3: Setting Elantech touchpad

To know more: https://gitlab.com/alfix/nsysctl.