<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.2.0">Jekyll</generator><link href="https://alfix.gitlab.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://alfix.gitlab.io/" rel="alternate" type="text/html" /><updated>2021-04-29T00:42:10+00:00</updated><id>https://alfix.gitlab.io/feed.xml</id><title type="html">Alfonso Siciliano</title><subtitle>Alfonso Siciliano Coding, BSD, and so on.
</subtitle><entry><title type="html">FreeBSD System Calls Table</title><link href="https://alfix.gitlab.io/bsd/coding/2021/01/02/freebsd-system-calls-table.html" rel="alternate" type="text/html" title="FreeBSD System Calls Table" /><published>2021-01-02T18:00:00+00:00</published><updated>2021-01-02T18:00:00+00:00</updated><id>https://alfix.gitlab.io/bsd/coding/2021/01/02/freebsd-system-calls-table</id><content type="html" xml:base="https://alfix.gitlab.io/bsd/coding/2021/01/02/freebsd-system-calls-table.html">&lt;p&gt;The “&lt;a href=&quot;https://alfonsosiciliano.gitlab.io/posts/2021-01-02-freebsd-system-calls-table.html&quot;&gt;FreeBSD syscalls table&lt;/a&gt;”
is available on the &lt;a href=&quot;https://alfonsosiciliano.gitlab.io/&quot;&gt;new Blog&lt;/a&gt;.&lt;/p&gt;</content><author><name></name></author><category term="bsd" /><category term="coding" /><summary type="html">The “FreeBSD syscalls table” is available on the new Blog.</summary></entry><entry><title type="html">Disable sysctl ANYBODY flag</title><link href="https://alfix.gitlab.io/bsd/2020/07/11/disable-sysctl-anybody-flag.html" rel="alternate" type="text/html" title="Disable sysctl ANYBODY flag" /><published>2020-07-11T18:00:00+00:00</published><updated>2020-07-11T18:00:00+00:00</updated><id>https://alfix.gitlab.io/bsd/2020/07/11/disable-sysctl-anybody-flag</id><content type="html" xml:base="https://alfix.gitlab.io/bsd/2020/07/11/disable-sysctl-anybody-flag.html">&lt;p&gt;&lt;a href=&quot;https://www.freebsd.org/&quot;&gt;FreeBSD&lt;/a&gt; provides the
&lt;a href=&quot;https://man.freebsd.org/sysctl/3&quot;&gt;sysctl&lt;/a&gt; system call and a &lt;em&gt;wrapper&lt;/em&gt;
&lt;a href=&quot;https://man.freebsd.org/sysctl/8&quot;&gt;utility&lt;/a&gt; to get or set the state of the
kernel at run time (the
&lt;a href=&quot;https://www.freebsd.org/doc/handbook/configtuning-sysctl.html&quot;&gt;handbook&lt;/a&gt; shows
some useful example). Every user can get the value of a parameter:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% sysctl kern.maxprocperuid
kern.maxprocperuid: 6656
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;but, only the root user can usually set a value.
&lt;!--preview--&gt;
Example:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% sysctl kern.maxprocperuid=10000
kern.maxprocperuid: 6656
sysctl: kern.maxprocperuid=10000: Operation not permitted
% su
# sysctl kern.maxprocperuid=10000
kern.maxprocperuid: 6656 -&amp;gt; 10000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Some parameter has the CTLFLAG_ANYBODY flag, so it is settable by every user.
We can use the
&lt;a href=&quot;https://alfix.gitlab.io/bsd/2019/02/19/nsysctl-tutorial.html&quot;&gt;nsysctl&lt;/a&gt; utility
to find them:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% nsysctl -aNGI | grep ANYBODY
kern.proc.args:  RD WR RW ANYBODY MPSAFE CAPWR
kern.proc.rlimit:  RD WR RW ANYBODY MPSAFE
kern.proc.osrel:  RD WR RW ANYBODY MPSAFE
kern.devname:  RD WR RW ANYBODY MPSAFE
hw.psm.elantech.natural_scroll:  RD WR RW ANYBODY DYN
hw.psm.elantech.three_finger_drag:  RD WR RW ANYBODY DYN
hw.psm.elantech.touchpad_off:  RD WR RW ANYBODY DYN
hw.psm.elantech.vscroll_div_max:  RD WR RW ANYBODY DYN
hw.psm.elantech.vscroll_div_min:  RD WR RW ANYBODY DYN
hw.psm.elantech.vscroll_min_delta:  RD WR RW ANYBODY DYN
hw.psm.elantech.vscroll_ver_area:  RD WR RW ANYBODY DYN
hw.psm.elantech.vscroll_hor_area:  RD WR RW ANYBODY DYN
hw.psm.elantech.taphold_timeout:  RD WR RW ANYBODY DYN
hw.psm.elantech.tap_min_queue:  RD WR RW ANYBODY DYN
hw.psm.elantech.tap_max_delta:  RD WR RW ANYBODY DYN
hw.psm.elantech.div_len:  RD WR RW ANYBODY DYN
hw.psm.elantech.div_max_na:  RD WR RW ANYBODY DYN
hw.psm.elantech.div_max:  RD WR RW ANYBODY DYN
hw.psm.elantech.div_min:  RD WR RW ANYBODY DYN
hw.psm.elantech.weight_len_squared:  RD WR RW ANYBODY DYN
hw.psm.elantech.weight_previous_na:  RD WR RW ANYBODY DYN
hw.psm.elantech.weight_previous:  RD WR RW ANYBODY DYN
hw.psm.elantech.weight_current:  RD WR RW ANYBODY DYN
hw.psm.elantech.multiplicator:  RD WR RW ANYBODY DYN
hw.psm.elantech.window_max:  RD WR RW ANYBODY DYN
hw.psm.elantech.window_min:  RD WR RW ANYBODY DYN
hw.psm.elantech.na_left:  RD WR RW ANYBODY DYN
hw.psm.elantech.na_bottom:  RD WR RW ANYBODY DYN
hw.psm.elantech.na_right:  RD WR RW ANYBODY DYN
hw.psm.elantech.na_top:  RD WR RW ANYBODY DYN
hw.psm.elantech.margin_left:  RD WR RW ANYBODY DYN
hw.psm.elantech.margin_bottom:  RD WR RW ANYBODY DYN
hw.psm.elantech.margin_right:  RD WR RW ANYBODY DYN
hw.psm.elantech.margin_top:  RD WR RW ANYBODY DYN
hw.psm.elantech.max_width:  RD WR RW ANYBODY DYN
hw.psm.elantech.max_pressure:  RD WR RW ANYBODY DYN
hw.psm.elantech.min_pressure:  RD WR RW ANYBODY DYN
hw.psm.elantech.two_finger_scroll:  RD WR RW ANYBODY DYN MPSAFE
hw.psm.elantech.max_y:  RD ANYBODY DYN MPSAFE
hw.psm.elantech.max_x:  RD ANYBODY DYN MPSAFE
hw.psm.elantech.directional_scrolls:  RD WR RW ANYBODY DYN MPSAFE
hw.snd.default_unit:  RD WR RW ANYBODY TUN RDTUN RWTUN NOFETCH
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Generally they are the parameters for setting up a Desktop/Laptop, &lt;em&gt;hw.psm.*&lt;/em&gt;
for the touchpad and &lt;em&gt;hw.snd.default_unit&lt;/em&gt; to define the default audio unit,
the others parameters are not writable because are &lt;em&gt;CTLTYPE_NODE&lt;/em&gt;s&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% nsysctl -Nt kern.proc.args kern.proc.rlimit kern.proc.osrel kern.devname
kern.proc.args: node
kern.proc.rlimit: node
kern.proc.osrel: node
kern.devname: opaque
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;or &lt;em&gt;CTLTYPE_OPAQUE&lt;/em&gt; (&lt;a href=&quot;https://man.freebsd.org/devname/3&quot;&gt;devname(3)&lt;/a&gt;).&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I think this flag is an useful feature, indeed a not-root user can use
&lt;a href=&quot;https://gitlab.com/alfix/mixertui&quot;&gt;mixertui&lt;/a&gt; to set &lt;em&gt;hw.snd.default_unit&lt;/em&gt; just
pressing &lt;em&gt;F8&lt;/em&gt;. However, a question in the FreeBSD hacker mailing list was about
“an option to disable CTLFLAG_ANYBODY flag: only the root user should set a
sysctl value”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution 1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first solution was to change an &lt;em&gt;if&lt;/em&gt; condition in
&lt;a href=&quot;https://github.com/freebsd/freebsd/blob/master/sys/kern/kern_sysctl.c&quot;&gt;kern_sysctl.c&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;	&lt;span class=&quot;cm&quot;&gt;/* Is this sysctl writable by only privileged users? */&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newptr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oid_kind&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CTLFLAG_ANYBODY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;priv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oid_kind&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CTLFLAG_PRISON&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;priv&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PRIV_SYSCTL_WRITEJAIL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#ifdef VIMAGE
&lt;/span&gt;		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oid_kind&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CTLFLAG_VNET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
		     &lt;span class=&quot;n&quot;&gt;prison_owns_vnet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;td&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;td_ucred&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;priv&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PRIV_SYSCTL_WRITEJAIL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif
&lt;/span&gt;		&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
			&lt;span class=&quot;n&quot;&gt;priv&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PRIV_SYSCTL_WRITE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;priv_check&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;td&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;priv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;goto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;from&lt;/p&gt;
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/* Is this sysctl writable by only privileged users? */&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newptr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oid_kind&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CTLFLAG_ANYBODY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;to&lt;/p&gt;
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/* Is this sysctl writable? */&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;so, the ANYBODY flag is deleted: sysctl() has to call/check
&lt;a href=&quot;https://man.freebsd.org/priv_check/9&quot;&gt;priv_check()&lt;/a&gt; every time a new value is
passed. This solution is correct because only the root user can set a value
but it has a problem: a normal user can’t use the utility to get a value:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% sysctl hw.snd.default_unit
sysctl: unknown oid &apos;hw.snd.default_unit&apos;
% su
# sysctl hw.snd.default_unit
hw.snd.default_unit: 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Solution 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What is the &lt;em&gt;unknown oid&lt;/em&gt; error with a not-root user?&lt;br /&gt;
The utility uses a special sysctl object: &lt;em&gt;sysctl.name2oid&lt;/em&gt; to convert
the name of a parameter in its corresponding &lt;em&gt;Object ID&lt;/em&gt;, indeed the system
call uses a numeric ID (&lt;em&gt;OID&lt;/em&gt;) to specify a parameter &lt;strong&gt;not its name&lt;/strong&gt;. The
utility calls sysctl() with the name in the &lt;em&gt;new buffer&lt;/em&gt; (&lt;em&gt;req-&amp;gt;newptr&lt;/em&gt;) and
&lt;em&gt;sysctl.name2oid&lt;/em&gt; fills the old buffer with the OID, pseudocode:&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;sysctl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sysctl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name2oid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;OID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sizeOID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strlen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;sysctl&lt;/em&gt; thinks to set a new value to the parameter, but after the
first solution only the root can set a new value so the error of the utility:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sysctl: unknown oid &apos;hw.snd.default_unit&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Another solution solves the problem, changing the previous &lt;em&gt;if&lt;/em&gt; condition in
kern_sysctl.c:&lt;/p&gt;

&lt;p&gt;from&lt;/p&gt;
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/* Is this sysctl writable by only privileged users? */&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newptr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oid_kind&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CTLFLAG_ANYBODY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;to&lt;/p&gt;
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/*
 * Is this sysctl writable?
 * Does it belong to the undocumented interface or sysctlinfo?
 */&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newptr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SYSCTL_CHILDREN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sysctl___sysctl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oid_parent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Testing: a not-root user can get the value of an object&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% sysctl hw.snd.default_unit
hw.snd.default_unit: 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;but cannot set a value&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% sysctl hw.snd.default_unit=0
hw.snd.default_unit: 1
sysctl: hw.snd.default_unit=0: Operation not permitted
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;despite the object has the ANYBODY flag&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% nsysctl -NG hw.snd.default_unit
hw.snd.default_unit:  RD WR RW ANYBODY TUN RDTUN RWTUN NOFETCH
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Technical study&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A not-root user can use the sysctl utility (with the second solution) because it
can “set” a new value to &lt;em&gt;sysctl.name2oid&lt;/em&gt;, properly &lt;em&gt;sysctl.name2oid&lt;/em&gt; belongs
to an undocumented kernel interface, you could refer to the README of the
&lt;a href=&quot;https://gitlab.com/alfix/sysctlinfo&quot;&gt;sysctlinfo&lt;/a&gt; interface for a more thorough
description.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;Links&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;FreeBSD hacker mailing list&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://lists.freebsd.org/pipermail/freebsd-hackers/2020-June/056200.html&quot;&gt;Solution 1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://lists.freebsd.org/pipermail/freebsd-hackers/2020-June/056202.html&quot;&gt;Solution 2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><category term="bsd" /><summary type="html">FreeBSD provides the sysctl system call and a wrapper utility to get or set the state of the kernel at run time (the handbook shows some useful example). Every user can get the value of a parameter: % sysctl kern.maxprocperuid kern.maxprocperuid: 6656 but, only the root user can usually set a value.</summary></entry><entry><title type="html">BSDCan 2020</title><link href="https://alfix.gitlab.io/bsd/2020/06/19/bsdcan-2020.html" rel="alternate" type="text/html" title="BSDCan 2020" /><published>2020-06-19T18:00:00+00:00</published><updated>2020-06-19T18:00:00+00:00</updated><id>https://alfix.gitlab.io/bsd/2020/06/19/bsdcan-2020</id><content type="html" xml:base="https://alfix.gitlab.io/bsd/2020/06/19/bsdcan-2020.html">&lt;p&gt;&lt;a href=&quot;https://www.bsdcan.org&quot;&gt;BSDCan&lt;/a&gt; is an annual technical conference &lt;em&gt;for people 
working on and with 4.4BSD based operating systems and related projects&lt;/em&gt;.&lt;br /&gt;
I had the honor of being a speaker this year, my talk was: 
“&lt;a href=&quot;https://www.bsdcan.org/events/bsdcan_2020/schedule/session/48-sysctlinfo-a-new-interface-to-visit-the-freebsd-sysctl-mib-and-to-pass-the-objects-info-to-userland/&quot;&gt;sysctlinfo: a new interface to visit the FreeBSD sysctl MIB and to pass the object info to userland&lt;/a&gt;”
(video, slides and paper are available online).&lt;/p&gt;</content><author><name></name></author><category term="bsd" /><summary type="html">BSDCan is an annual technical conference for people working on and with 4.4BSD based operating systems and related projects. I had the honor of being a speaker this year, my talk was: “sysctlinfo: a new interface to visit the FreeBSD sysctl MIB and to pass the object info to userland” (video, slides and paper are available online).</summary></entry><entry><title type="html">MixerTUI 1.1</title><link href="https://alfix.gitlab.io/bsd/2020/04/24/mixertui-1-1.html" rel="alternate" type="text/html" title="MixerTUI 1.1" /><published>2020-04-24T18:00:00+00:00</published><updated>2020-04-24T18:00:00+00:00</updated><id>https://alfix.gitlab.io/bsd/2020/04/24/mixertui-1-1</id><content type="html" xml:base="https://alfix.gitlab.io/bsd/2020/04/24/mixertui-1-1.html">&lt;p&gt;&lt;strong&gt;MixerTUI 1.1 is out!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://gitlab.com/alfix/mixertui&quot;&gt;MixerTUI&lt;/a&gt; is an audio mixer with a Terminal
User Interface for &lt;a href=&quot;https://www.freebsd.org&quot;&gt;FreeBSD&lt;/a&gt;, the new features of this
version are: -d -h -m -v options and TAB to switch view mode.
&lt;!--preview--&gt;&lt;/p&gt;

&lt;p&gt;To install the port &lt;a href=&quot;https://www.freshports.org/audio/mixertui&quot;&gt;audio/mixertui&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# cd /usr/ports/audio/mixertui/ &amp;amp;&amp;amp; make install clean
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To add the package:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# pkg install mixertui
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/mixertui1-1.png&quot; alt=&quot;mixertui 0.1 screenshot&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Options and features:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SYNOPSIS
     mixertui [-c | -h | -v] [-d &amp;lt;unit&amp;gt;] [-m &amp;lt;mixer&amp;gt;]

DESCRIPTION
     The mixertui utility is an audio mixer with a Terminal User Interface.

     The following options are available:

     -c      Disable color.

     -d &amp;lt;unit&amp;gt;
             Show the device with the &amp;lt;unit&amp;gt; number, default sysctl
             hw.snd.default_unit.

     -h      Display options, a short description and exit.

     -m &amp;lt;mixer&amp;gt;
             Use &amp;lt;mixer&amp;gt; to get the list of devices, default /dev/mixer.

     -v      Show version and exit.

     The following user interface features are available:

     Esc Q q
             Exit.

     F1 ? H h
             Open Help window.

     F2      Show Sound Driver information.

     F3      Playback View: show playback controls.

     F4      Capture View: show capture controls.

     F5      All View: show all controls.

     TAB     Switch View F3/F4/F5.

     F6      Select audio device.

     F7      Show audio device information.

     F8      Set current device as default.

     R r     Refresh screen.

     KEY_LEFT
             Previous control.

     KEY_RIGHT
             Next control.

     KEY_UP/KEY_DOWN
             Increment/Decrement volume.

     +/-     Increment/Decrement volume.

     PAGE_UP/PAGE_DOWN
             Increment/Decrement volume in a big step.

     End     Set volume to 0%.

     Home    Set volume to 100%.

     0-9     Set volume to 0%-90%.

     a/s/d   Increment left/both/right volume.

     z/x/c   Decrement left/both/right volume.

     B b     Balance left and right volume.

     M m     Toggle mute.

     &amp;lt;/&amp;gt;     Toggle left/right mute.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="bsd" /><summary type="html">MixerTUI 1.1 is out! MixerTUI is an audio mixer with a Terminal User Interface for FreeBSD, the new features of this version are: -d -h -m -v options and TAB to switch view mode.</summary></entry><entry><title type="html">MixerTUI 0.1</title><link href="https://alfix.gitlab.io/bsd/2020/04/02/mixertui-0-1.html" rel="alternate" type="text/html" title="MixerTUI 0.1" /><published>2020-04-02T18:00:00+00:00</published><updated>2020-04-02T18:00:00+00:00</updated><id>https://alfix.gitlab.io/bsd/2020/04/02/mixertui-0-1</id><content type="html" xml:base="https://alfix.gitlab.io/bsd/2020/04/02/mixertui-0-1.html">&lt;p&gt;&lt;strong&gt;MixerTUI 0.1 is out!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://gitlab.com/alfix/mixertui&quot;&gt;MixerTUI&lt;/a&gt; is an audio mixer with a Terminal
User Interface built on the &lt;a href=&quot;https://www.freebsd.org&quot;&gt;FreeBSD&lt;/a&gt; sound system
&lt;a href=&quot;https://wiki.freebsd.org/Sound&quot;&gt;wiki.freebsd.org/Sound&lt;/a&gt;.
It can show the current Sound Driver configuration and select an audio device:
to get its information, change the volume or to set as default, the last
feature allows to switch easily audio from/to laptop and hdmi, headphones and
speakers, etc.
&lt;!--preview--&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/mixertui0-1.png&quot; alt=&quot;mixertui 0.1 screenshot&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To install the port &lt;a href=&quot;https://www.freshports.org/audio/mixertui&quot;&gt;audio/mixertui&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# cd /usr/ports/audio/mixertui/ &amp;amp;&amp;amp; make install clean
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To add the package:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# pkg install mixertui
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To build from the repository:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% git clone https://gitlab.com/alfix/mixertui.git
% cd mixertui
% make
% ./mixertui
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Options and features:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SYNOPSIS
     mixertui [-c]

DESCRIPTION
     The mixertui utility is an audio mixer with a Terminal User Interface.

     The following option is available:

     -c      Disable color.

     The following user interface features are available:

     Esc Q q
             Exit.

     F1 H h  Open Help window.

     F2      Show Sound Driver information.

     F3      Playback View: show playback controls.

     F4      Capture View: show capture controls.

     F5      All View: show all controls.

     F6      Select audio device.

     F7      Show audio device information.

     F8      Set current device as default.

     R r     Refresh screen.

     KEY_LEFT
             Previous control.

     KEY_RIGHT
             Next control.

     KEY_UP/KEY_DOWN
             Increment/Decrement volume.

     +/-     Increment/Decrement volume.

     PAGE_UP/PAGE_DOWN
             Increment/Decrement volume in a big step.

     End     Set volume to 0%.

     0-9     Set volume to 0%-90%.

     a/s/d   Increment left/both/right volume.

     z/x/c   Decrement left/both/right volume.

     B b     Balance left and right volume.

     M m     Toggle mute.

     &amp;lt;/&amp;gt;     Toggle left/right mute.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="bsd" /><summary type="html">MixerTUI 0.1 is out! MixerTUI is an audio mixer with a Terminal User Interface built on the FreeBSD sound system wiki.freebsd.org/Sound. It can show the current Sound Driver configuration and select an audio device: to get its information, change the volume or to set as default, the last feature allows to switch easily audio from/to laptop and hdmi, headphones and speakers, etc.</summary></entry><entry><title type="html">sysctlview 2.0</title><link href="https://alfix.gitlab.io/bsd/2020/03/29/sysctlview-2-0.html" rel="alternate" type="text/html" title="sysctlview 2.0" /><published>2020-03-29T19:00:00+00:00</published><updated>2020-03-29T19:00:00+00:00</updated><id>https://alfix.gitlab.io/bsd/2020/03/29/sysctlview-2-0</id><content type="html" xml:base="https://alfix.gitlab.io/bsd/2020/03/29/sysctlview-2-0.html">&lt;p&gt;&lt;strong&gt;sysctlview 2.0 is out!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://man.freebsd.org/sysctl/3&quot;&gt;sysctl()&lt;/a&gt; system call can get or set the
state of the system, the &lt;a href=&quot;https://www.freebsd.org&quot;&gt;FreeBSD&lt;/a&gt; kernel exposes the
parameters for &lt;em&gt;sysctl()&lt;/em&gt; as objects of a &lt;em&gt;Management information Base&lt;/em&gt; (MIB).&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://gitlab.com/alfix/sysctlview&quot;&gt;sysctlview&lt;/a&gt; is a graphical sysctl MIB
explorer, it shows the properties and the value of an object, the new version 2
allows to set its value, too.
&lt;!--preview--&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/sysctlview2-0.png&quot; alt=&quot;sysctl 2.0 screenshot&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To install the port
&lt;a href=&quot;https://www.freshports.org/deskutils/sysctlview&quot;&gt;deskutils/sysctlview&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# cd /usr/ports/deskutils/sysctlview/ &amp;amp;&amp;amp; make install clean
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To add the package:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# pkg install sysctlview
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="bsd" /><summary type="html">sysctlview 2.0 is out! The sysctl() system call can get or set the state of the system, the FreeBSD kernel exposes the parameters for sysctl() as objects of a Management information Base (MIB). sysctlview is a graphical sysctl MIB explorer, it shows the properties and the value of an object, the new version 2 allows to set its value, too.</summary></entry><entry><title type="html">FreeBSD and Nvidia Optimus</title><link href="https://alfix.gitlab.io/bsd/2020/01/05/freebsd-and-nvidia-optimus.html" rel="alternate" type="text/html" title="FreeBSD and Nvidia Optimus" /><published>2020-01-05T19:00:00+00:00</published><updated>2020-01-05T19:00:00+00:00</updated><id>https://alfix.gitlab.io/bsd/2020/01/05/freebsd-and-nvidia-optimus</id><content type="html" xml:base="https://alfix.gitlab.io/bsd/2020/01/05/freebsd-and-nvidia-optimus.html">&lt;p&gt;This post is a “step by step” tutorial to describe how I can use my Nvidia 
GeForce GT540M graphic card of my FreeBSD laptop,
&lt;a href=&quot;https://twitter.com/alfsiciliano/status/1185570967189426177&quot;&gt;screenshot&lt;/a&gt;.
&lt;!--preview--&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.freebsd.org/&quot;&gt;FreeBSD&lt;/a&gt; is a registered trademark of the
&lt;a href=&quot;https://www.freebsdfoundation.org/&quot;&gt;FreeBSD Foundation&lt;/a&gt;,
&lt;a href=&quot;https://www.nvidia.com/en-us/about-nvidia/legal-info/&quot;&gt;NVIDIA&lt;/a&gt; and
&lt;a href=&quot;https://www.nvidia.com/en-us/about-nvidia/legal-info/&quot;&gt;Optimus&lt;/a&gt;
are registered trademarks of the
&lt;a href=&quot;https://www.nvidia.com&quot;&gt;NVIDIA Corporation&lt;/a&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;“Step 0”&lt;/strong&gt;&lt;br /&gt;
I assume you are using FreeBSD and have a Nvidia
&lt;a href=&quot;https://www.geforce.com/hardware/technology/optimus&quot;&gt;Optimus&lt;/a&gt; graphic card.
My laptop is
&lt;a href=&quot;https://wiki.freebsd.org/Laptops/Acer_Aspire_5742G&quot;&gt;wiki.freebsd.org/Laptops/Acer_Aspire_5742G&lt;/a&gt;,
at the time of writing my FreeBSD version is:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% uname -a
FreeBSD fbsd.home 13.0-CURRENT FreeBSD 13.0-CURRENT r352742 GENERIC  amd64
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I can use the Intel video card by installing
&lt;a href=&quot;https://www.freshports.org/graphics/drm-current-kmod&quot;&gt;graphics/drm-current-kmod&lt;/a&gt;
(you may need to install &lt;em&gt;drm-fbsd12.0-kmod&lt;/em&gt; or &lt;em&gt;drm-fbsd11.2-kmod&lt;/em&gt;), following
the
&lt;a href=&quot;https://svnweb.freebsd.org/ports/head/graphics/drm-current-kmod/pkg-message?revision=508877&amp;amp;view=markup&quot;&gt;instructions&lt;/a&gt;
of the port and editing the &lt;em&gt;Section “Device”&lt;/em&gt; of /etc/X11/xorg.conf:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-xorg&quot;&gt;... extra ...

Section &quot;Device&quot;
        ### Available Driver options are:-
        ### Values: &amp;lt;i&amp;gt;: integer, &amp;lt;f&amp;gt;: float, &amp;lt;bool&amp;gt;: &quot;True&quot;/&quot;False&quot;,
        ### &amp;lt;string&amp;gt;: &quot;String&quot;, &amp;lt;freq&amp;gt;: &quot;&amp;lt;f&amp;gt; Hz/kHz/MHz&quot;,
        ### &amp;lt;percent&amp;gt;: &quot;&amp;lt;f&amp;gt;%&quot;
        ### [arg]: arg optional
        #Option     &quot;ShadowFB&quot;           	# [&amp;lt;bool&amp;gt;]
        #Option     &quot;DefaultRefresh&quot;     	# [&amp;lt;bool&amp;gt;]
        #Option     &quot;ModeSetClearScreen&quot; 	# [&amp;lt;bool&amp;gt;]
	Identifier  &quot;Card0&quot;
	Driver      &quot;intel&quot;
	BusID       &quot;PCI:0:2:0&quot;
EndSection

#Section &quot;Device&quot;
        ### Available Driver options are:-
        ### Values: &amp;lt;i&amp;gt;: integer, &amp;lt;f&amp;gt;: float, &amp;lt;bool&amp;gt;: &quot;True&quot;/&quot;False&quot;,
        ### &amp;lt;string&amp;gt;: &quot;String&quot;, &amp;lt;freq&amp;gt;: &quot;&amp;lt;f&amp;gt; Hz/kHz/MHz&quot;,
        ### &amp;lt;percent&amp;gt;: &quot;&amp;lt;f&amp;gt;%&quot;
        ### [arg]: arg optional
        #Option     &quot;ShadowFB&quot;           	# [&amp;lt;bool&amp;gt;]
        #Option     &quot;DefaultRefresh&quot;     	# [&amp;lt;bool&amp;gt;]
        #Option     &quot;ModeSetClearScreen&quot; 	# [&amp;lt;bool&amp;gt;]
	#Identifier  &quot;Card1&quot;
	#Driver      &quot;vesa&quot;
	#BusID       &quot;PCI:1:0:0&quot;
#EndSection

... extra ...
&lt;/code&gt;&lt;/pre&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;“Step 1”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Install the Nvidia driver and the optirun utility:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% git clone https://github.com/pouya-eghbali/freebsd-nvidia-optimus.git
% cd freebsd-nvidia-optimus
% sudo mkdir /usr/ports/x11/nvidia-optimus-driver
% sudo cp -pr ./nvidia-optimus-driver /usr/ports/x11
% sudo mkdir /usr/ports/x11/nvidia-optimus-driver-390
% sudo cp -pr ./nvidia-optimus-driver-390 /usr/ports/x11
% cd /usr/ports/x11/nvidia-optimus-driver-390 ; sudo make install clean
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;I installed the legacy version 390, you could install the latest version:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% cd /usr/ports/x11/nvidia-optimus-driver ; sudo make install clean
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Finally you may need to run:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% rehash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;“Step 2”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start the Optimus service:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% sudo /usr/local/etc/rc.d/optimus onestart
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The output is:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% sudo /usr/local/etc/rc.d/optimus onestart
Starting optimus
% 
X.Org X Server 1.18.4
Release Date: 2016-07-19
X Protocol Version 11, Revision 0
Build Operating System: FreeBSD 13.0-CURRENT amd64 
Current Operating System: FreeBSD fbsd.home 13.0-CURRENT FreeBSD 13.0-CURRENT r352742 GENERIC amd64
Build Date: 26 September 2019  06:56:18AM
 
Current version of pixman: 0.38.4
	Before reporting problems, check http://wiki.x.org
	to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
	(++) from command line, (!!) notice, (II) informational,
	(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: &quot;/var/log/Xorg.8.log&quot;, Time: Sun Jan  5 03:32:11 2020
(++) Using config file: &quot;/usr/local/etc/X11/optimus.x.conf&quot;
(==) Using system config directory &quot;/usr/local/share/X11/xorg.conf.d&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The command could lock the shell, no problem, just type the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enter&lt;/code&gt; key&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;Press ENTER&amp;gt;

% 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The shell is again ready to run your commands.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;“&lt;strong&gt;Step 3&lt;/strong&gt;”&lt;/p&gt;

&lt;p&gt;Install &lt;a href=&quot;https://www.freshports.org/games/trigger-rally&quot;&gt;games/trigger-rally&lt;/a&gt;
(&lt;a href=&quot;http://trigger-rally.sourceforge.net/&quot;&gt;http://trigger-rally.sourceforge.net/&lt;/a&gt;)
and run it&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% trigger-rally
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Don’t play, close the game, the output should show:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;...
Graphics: Intel Open Source Technology Center Mesa DRI Intel(R) Ironlake Mobile 
Using OpenGL 2.1 Mesa 18.3.2
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now run&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;% optirun trigger-rally
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Close the game, finally you can see:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;...
Graphics: NVIDIA Corporation GeForce GT 540M/PCIe/SSE2
Using OpenGL 4.5.0 NVIDIA 390.116
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Alike you could install games/sauerbraten, the info about the graphic card is
at the top-left corner of the starting screen
&lt;a href=&quot;https://twitter.com/alfsiciliano/status/1213988405933199361&quot;&gt;screenshot&lt;/a&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;“&lt;strong&gt;Step 4&lt;/strong&gt;”&lt;/p&gt;

&lt;p&gt;Enjoy! Some screenshot:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;games/trigger-rally
&lt;a href=&quot;https://twitter.com/alfsiciliano/status/1155731403268603905&quot;&gt;screenshot1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;games/0ad
&lt;a href=&quot;https://twitter.com/alfsiciliano/status/1163584080828649473&quot;&gt;screenshot2&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;games/sauerbraten
&lt;a href=&quot;https://twitter.com/alfsiciliano/status/1167155673035091972&quot;&gt;screenshot3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;“&lt;strong&gt;Step 5&lt;/strong&gt;”&lt;/p&gt;

&lt;p&gt;Github project: 
&lt;a href=&quot;https://github.com/pouya-eghbali/freebsd-nvidia-optimus&quot;&gt;pouya-eghbali/freebsd-nvidia-optimus&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;FreeBSD port x11/nvidia-driver-optimus (Work In Progress): 
&lt;a href=&quot;https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=192617&quot;&gt;PR 192617&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Problems and Troubleshoot: 
&lt;a href=&quot;https://forums.freebsd.org/threads/nvidia-optimus-driver-for-freebsd.71504/&quot;&gt;FreeBSD Forum “nvidia optimus driver for freebsd”&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Switch off the Nvidia Optimus card: 
&lt;a href=&quot;https://wiki.freebsd.org/TuningPowerConsumption#NVIDIA_Optimus&quot;&gt;FreeBSD wiki “TuningPowerConsumption”&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="bsd" /><summary type="html">This post is a “step by step” tutorial to describe how I can use my Nvidia GeForce GT540M graphic card of my FreeBSD laptop, screenshot.</summary></entry><entry><title type="html">Manual sysctlmibinfo2</title><link href="https://alfix.gitlab.io/bsd/2019/12/09/manual-sysctlmibinfo2.html" rel="alternate" type="text/html" title="Manual sysctlmibinfo2" /><published>2019-12-09T19:00:00+00:00</published><updated>2019-12-09T19:00:00+00:00</updated><id>https://alfix.gitlab.io/bsd/2019/12/09/manual-sysctlmibinfo2</id><content type="html" xml:base="https://alfix.gitlab.io/bsd/2019/12/09/manual-sysctlmibinfo2.html">&lt;p&gt;The &lt;a href=&quot;https://gitlab.com/alfix/sysctlmibinfo2&quot;&gt;sysctlmibinfo2&lt;/a&gt; library provides 
an API to explore the &lt;a href=&quot;https://www.freebsd.org/&quot;&gt;FreeBSD&lt;/a&gt; sysctl MIB and to get 
the info of an object, it is useful to build a 
&lt;a href=&quot;https://man.freebsd.org/sysctl/8&quot;&gt;sysctl&lt;/a&gt;-like tool to get or set the kernel 
state. For example, &lt;a href=&quot;https://gitlab.com/alfix/sysctlview&quot;&gt;sysctlview&lt;/a&gt;, 
a graphical sysctl MIB explorer, depends on it.
&lt;!--preview--&gt;&lt;/p&gt;

&lt;p&gt;This post shows the manual page, for the source code and examples:
&lt;a href=&quot;https://gitlab.com/alfix/sysctlmibinfo2&quot;&gt;gitlab.com/alfix/sysctlmibinfo2&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SYSCTLMIBINFO2(3)      FreeBSD Library Functions Manual      SYSCTLMIBINFO2(3)

NAME
     sysctlmif_name, sysctlmif_oidbyname, sysctlmif_oidinputbyname,
     sysctlmif_desc, sysctlmif_descbyname, sysctlmif_label,
     sysctlmif_labelbyname, sysctlmif_fmt, sysctlmif_fmtbyname,
     sysctlmif_kind, sysctlmif_kindbyname, SYSCTLMIF_KINDTYPE,
     SYSCTLMIF_KINDFLAGS, sysctlmif_nextnode, sysctlmif_nextleaf,
     sysctlmif_object, sysctlmif_objectbyname, sysctlmif_freeobject,
     sysctlmif_list, sysctlmif_grouplist, sysctlmif_grouplistbyname,
     sysctlmif_freelist, sysctlmif_tree, sysctlmif_treebyname,
     sysctlmif_freetree, sysctlmif_mib, sysctlmif_freemib - sysctl MIB-Tree
     info API

LIBRARY
     To load the required kernel modules at boot time, place the following
     lines in loader.conf(5):

           sysctlinfo_load=&quot;YES&quot;
           sysctlbyname_improved_load=&quot;YES&quot;

     library &quot;libsysctlmibinfo2&quot;

SYNOPSIS
     #include &amp;lt;sys/types.h&amp;gt;
     #include &amp;lt;sys/queue.h&amp;gt;
     #include &amp;lt;sysctlmibinfo2.h&amp;gt;

     int
     sysctlmif_name(int *id, size_t idlevel, char *name, size_t *namelen);

     int
     sysctlmif_oidbyname(const char *name, int *id, size_t *idlevel);

     int
     sysctlmif_oidinputbyname(const char *name, int *id, size_t *idlevel);

     int
     sysctlmif_desc(int *id, size_t idlevel, char *desc, size_t *desclen);

     int
     sysctlmif_descbyname(const char *name, char *desc, size_t *desclen);

     int
     sysctlmif_label(int *id, size_t idlevel, char *label, size_t *labellen);

     int
     sysctlmif_labelbyname(const char *name, char *label, size_t *labellen);

     int
     sysctlmif_fmt(int *id, size_t idlevel, char *fmt, size_t *fmtlen);

     int
     sysctlmif_fmtbyname(const char *name, char *fmt, size_t *fmtlen);

     int
     sysctlmif_kind(int *id, size_t idlevel, unsigned int *kind);

     int
     sysctlmif_kindbyname(const char *name, unsigned int *kind);

     unsigned int
     SYSCTLMIF_KINDTYPE(unsigned int kind);

     unsigned int
     SYSCTLMIF_KINDFLAGS(unsigned int kind);

     int
     sysctlmif_nextleaf(int *id, size_t idlevel, int *idnext,
         size_t *idnextlevel);

     int
     sysctlmif_nextnode(int *id, size_t idlevel, int *idnext,
         size_t *idnextlevel);

     struct sysctlmif_object *
     sysctlmif_object(int *id, size_t idlevel);

     struct sysctlmif_object *
     sysctlmif_objectbyname(const char *name);

     void
     sysctlmif_freeobject(struct sysctlmif_object *object);

     struct sysctlmif_object_list *
     sysctlmif_list();

     struct sysctlmif_object_list *
     sysctlmif_grouplist(int *idroot, size_t idrootlen);

     struct sysctlmif_object_list *
     sysctlmif_grouplistbyname(const char *name);

     void
     sysctlmif_freelist(struct sysctlmif_object_list *list);

     struct sysctlmif_object *
     sysctlmif_tree(int *idroot, size_t idrootlevel);

     struct sysctlmif_object *
     sysctlmif_treebyname(const char *name);

     void
     sysctlmif_freetree(struct sysctlmif_object *node);

     struct sysctlmif_object_list *
     sysctlmif_mib();

     void
     sysctlmif_freemib(struct sysctlmif_object_list *mib);

DESCRIPTION
     The sysctlmibinfo2 library is an interface to the kernel sysctl MIB-Tree.
     It implements wrappers around the sysctlinfo(4) interface and
     sysctlbyname-improved to explore the sysctl MIB and to get the info of an
     object, moreover it defines a struct sysctlmif_object and provides a
     convenient API to build data structures of sysctlmif_object; as it is not
     designed to get and set object values, anyone wishing to do this should
     see sysctl(3).

     An object is identified by an Object Identifier (OID), it is represented
     by a pair int *id and size_t idlevel, the level should be between 1 and
     CTL_MAXNAME.

     sysctlmif_name(), sysctlmif_desc(), sysctlmif_kind(), sysctlmif_fmt(),
     sysctlmif_label(), sysctlmif_nextnode() and sysctlmif_nextleaf() set name
     and namelen, desc and desclen, kind, label and labellen, idnext and
     idnextlevel like the object with id / idlevel.  sysctlmif_descbyname(),
     sysctlmif_kindbyname(), sysctlmif_fmtbyname() and sysctlmif_labelbyname()
     are equivalet but the object is identified by its name.

     sysctlmif_oidbyname() and sysctlmif_oidinputbyname() set id and idlevel
     like the object with name, sysctlmif_oidinputbyname() can handle the
     nodes with an input with the OID, e.g., &quot;kern.proc.pid.&amp;lt;input&amp;gt;&quot;.

     The previous functions seek the object with id / idlevel or name, then
     the property is copied into the buffer (e.g., desc, label, idnext, etc.).
     Before the call buflen (e.g., desclen, lebellen, idnextlevel, etc.)
     gives the size of buffer, after a successful call buflen gives the amount
     of data copied; the size of the property can be determined with the NULL
     argument for the buffer, the size will be returned in the location
     pointed to by buflen.

     The sysctlmibinfo2 library defines a struct for the info of an object:

           struct sysctlmif_object {
                   SLIST_ENTRY(sysctlmif_object) object_link;
                   int *id;                     /* array of idlevel items    */
                   size_t idlevel;              /* between 1 and CTL_MAXNAME */
                   char *name;
                   char *desc;
                   char *label;                 /* aggregation label         */
                   uint8_t type;                /* defined in &amp;lt;sys/sysctl.h&amp;gt; */
                   uint32_t flags;              /* defined in &amp;lt;sys/sysctl.h&amp;gt; */
                   char *fmt;                   /* format string             */
                   struct sysctlmif_object_list *children; /* children list  */
           };

     and a list of objects, struct sysctlmif_object_list, iterable by the
     SLIST macros, see queue(3).

     sysctlmif_object() and sysctlmif_objectbyname() return a pointer to the
     allocated memory for a struct sysctlmif_object of the object with id /
     idlevel or name, the pointer can be passed to sysctlmif_freeobject() to
     free the memory.

     sysctlmif_list() allocates memory and returns a list with all the objects
     of the MIB, sysctlmif_freelist() frees the allocated memory.

     sysctlmif_grouplist() and sysctlmif_grouplistbyname() allocate memory and
     returns a list of the objects visited in a &quot;Depth First Traversal&quot;, id /
     idlevel or name denote the root, sysctlmif_freelist() frees the allocated
     memory.

     sysctlmif_tree() and sysctlmif_treebyname() allocate memory for a tree of
     sysctlmif_object and returns a pointer to the root, id / idlevel or name
     denote the root, object.children is set and iterable by SLIST macros,
     sysctlmif_freetree() frees the allocated memory.

     sysctlmif_mib() allocates memory for a collection of trees and returns a
     list where the entries are the roots representing the top-level objects,
     sysctlmif_freemib() frees the allocated memory.

RETURN VALUES
     The sysctlmif_name(), sysctlmif_oidbyname(), sysctlmif_oidinputbyname(),
     sysctlmif_desc(), sysctlmif_descbyname(), sysctlmif_label(),
     sysctlmif_labelbyname(), sysctlmif_fmt(), sysctlmif_fmtbyname(),
     sysctlmif_kind(), sysctlmif_kindbyname(), sysctlmif_nextnode(), and
     sysctlmif_nextleaf() functions return the value 0 if successful;
     otherwise the value -1 is returned and the global variable errno is set
     to indicate the error.

     The sysctlmif_object(), sysctlmif_objectbyname(), sysctlmif_list(),
     sysctlmif_grouplist(), sysctlmif_grouplistbyname(), sysctlmif_tree(),
     sysctlmif_treebyname(), sysctlmif_mib() functions return NULL upon error
     or a pointer to allocated memory for success.

EXAMPLES
     Complete set of examples:
           https://gitlab.com/alfix/sysctlmibinfo2/tree/master/examples

     Example to print the Sound Driver objects:

           struct sysctlmif_object_list *list;
           struct sysctlmif_object *obj;

           if ((list = sysctlmif_grouplistbyname(&quot;hw.snd&quot;)) == NULL)
                   return (1);

           SLIST_FOREACH(obj, list, object_link) {
                   printf(&quot;name:   %s\n&quot;, obj-&amp;gt;name);
                   printf(&quot;descr.: %s\n&quot;, obj-&amp;gt;desc);
                   printf(&quot;label:  %s\n&quot;, obj-&amp;gt;label);
                   printf(&quot;flags:  %u\n&quot;, obj-&amp;gt;flags);
                   printf(&quot;type:   %u\n&quot;, obj-&amp;gt;type);
                   printf(&quot;fmt:    %s\n&quot;, obj-&amp;gt;fmt);
                   printf(&quot;----------------------\n&quot;);
           }

           sysctlmif_freelist(list);

ERRORS
     The following errors may be reported:

     [ECAPMODE]         The node has not the CTLFLAG_CAPRD or CTLFLAG_CAPWR
                        flag in capability mode.

     [EINVAL]           name has more than CTL_MAXNAME levels.

     [EINVAL]           idlevel is either greater CTL_MAXNAME, equal to zero
                        or is not an integer.

     [ENAMETOOLONG]     name is &amp;gt;= MAXPATHLEN.

     [ENOATTR]          The node exists but its info is NULL.

     [ENOENT]           The node does not exist.

SEE ALSO
     cap_enter(2), queue(3), sysctl(3), sysctlinfo(3), sysctlinfo(4)

HISTORY
     The sysctlmibinfo2 library first appeared in FreeBSD 13.0.

AUTHORS
     sysctlmibinfo2 was written by Alfonso Sabato Siciliano
     &amp;lt;alf.siciliano@gmail.com&amp;gt;

FreeBSD 13.0-CURRENT             April 7, 2020            FreeBSD 13.0-CURRENT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="bsd" /><summary type="html">The sysctlmibinfo2 library provides an API to explore the FreeBSD sysctl MIB and to get the info of an object, it is useful to build a sysctl-like tool to get or set the kernel state. For example, sysctlview, a graphical sysctl MIB explorer, depends on it.</summary></entry><entry><title type="html">Manuals sysctlinfo</title><link href="https://alfix.gitlab.io/bsd/2019/10/02/manuals-sysctlinfo.html" rel="alternate" type="text/html" title="Manuals sysctlinfo" /><published>2019-10-02T19:00:00+00:00</published><updated>2019-10-02T19:00:00+00:00</updated><id>https://alfix.gitlab.io/bsd/2019/10/02/manuals-sysctlinfo</id><content type="html" xml:base="https://alfix.gitlab.io/bsd/2019/10/02/manuals-sysctlinfo.html">&lt;p&gt;sysctlinfo is an interface to explore the sysctl tree and to pass the 
properties of the nodes to the userland, this post displays the manuals 
(sysctlinfo.4 and sysctlinfo.3), for an introduction, examples and FAQ: 
&lt;a href=&quot;https://gitlab.com/alfix/sysctlinfo&quot;&gt;http://gitlab.com/alfix/sysctlinfo&lt;/a&gt;.
&lt;!--preview--&gt;&lt;/p&gt;

&lt;p&gt;Legal notice: &lt;a href=&quot;http://www.freebsd.org&quot;&gt;FreeBSD&lt;/a&gt; is a registered trademark 
of the &lt;a href=&quot;https://www.freebsdfoundation.org&quot;&gt;FreeBSD Foundation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;man 4 sysctlinfo&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SYSCTLINFO(4)          FreeBSD Kernel Interfaces Manual          SYSCTLINFO(4)

NAME
     sysctlinfo - a sysctl(3) MIB for getting info about the sysctl tree

SYNOPSIS
     sysctl sysctl.entryfakename
     sysctl sysctl.entryname
     sysctl sysctl.entrydesc
     sysctl sysctl.entrylabel
     sysctl sysctl.entrykind
     sysctl sysctl.entryfmt
     sysctl sysctl.entrynextnode
     sysctl sysctl.entrynextleaf
     sysctl sysctl.entryallinfo
     sysctl sysctl.entryallinfo_withnextnode
     sysctl sysctl.entryallinfo_withnextleaf
     sysctl sysctl.entryfakeidbyname
     sysctl sysctl.entryidbyname
     sysctl sysctl.entrydescbyname
     sysctl sysctl.entrylabelbyname
     sysctl sysctl.entrykindbyname
     sysctl sysctl.entryfmtbyname
     sysctl sysctl.entryallinfobyname
     sysctl sysctl.entryallinfobyname_withnextnode
     sysctl sysctl.entryallinfobyname_withnextleaf

DESCRIPTION
     The sysctlinfo interface explores the sysctl tree to pass the info of the
     nodes to userland, it should be used via sysctlinfo(3).

SEE ALSO
     sysctl(3), sysctlinfo(3)

HISTORY
     The sysctlinfo interface first appeared in FreeBSD 13.0.

AUTHORS
     The sysctlinfo interface was written by Alfonso S. Siciliano
     &amp;lt;alf.siciliano@gmail.com&amp;gt;

FreeBSD 13.0-CURRENT            August 2, 2019            FreeBSD 13.0-CURRENT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;man 3 sysctlinfo&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SYSCTLINFO(3)          FreeBSD Library Functions Manual          SYSCTLINFO(3)

NAME
     SYSCTLINFO SYSCTLINFO_BYNAME SYSCTLINFO_HELPER_ALL
     SYSCTLINFO_HELPER_ALLIWITHNEXT SYSCTLINFO_HELPER_ALLWITHNEXTNAME -
     Interface for getting info about the sysctl tree

SYNOPSIS
     #include &amp;lt;sys/types.h&amp;gt;
     #include &amp;lt;sys/sysctl.h&amp;gt;
     #include &amp;lt;sysctlinfo.h&amp;gt;

     #define ENTRYFAKENAME
     #define ENTRYNAME
     #define ENTRYDESC
     #define ENTRYLABEL
     #define ENTRYKIND
     #define ENTRYFMT
     #define ENTRYNEXTNODE
     #define ENTRYNEXTLEAF
     #define ENTRYALLINFO
     #define ENTRYALLINFO_WITHNEXTNODE
     #define ENTRYALLINFO_WITHNEXTLEAF
     #define ENTRYIDBYNAME
     #define ENTRYFAKEIDBYNAME
     #define ENTRYDESCBYNAME
     #define ENTRYLABELBYNAME
     #define ENTRYKINDBYNAME
     #define ENTRYFMTBYNAME
     #define ENTRYALLINFOBYNAME
     #define ENTRYALLINFOBYNAME_WITHNEXTNODE
     #define ENTRYALLINFOBYNAME_WITHNEXTLEAF

     int
     SYSCTLINFO(int *id, size_t idlevel, int prop[2], void *buf,
         size_t *buflen);

     int
     SYSCTLINFO_BYNAME(char *name, int prop[2], void *buf, size_t *buflen);

     void
     SYSCTLINFO_HELPER_ALL(void *buf, size_t idlevel, int *id, char *namep,
         char *descrp, unsigned int kind, char *fmtp, char *labelp);

     void
     SYSCTLINFO_HELPER_ALLWITHNEXT(void *buf, size_t idlevel, int *id,
         char *namep, char *descrp, unsigned int kind, char *fmtp,
         char *labelp, size_t idnextlevel, int *idnext);

     void
     SYSCTLINFO_HELPER_ALLWITHNEXTNAME(void *buf, size_t idlevel, int *id,
         char *namep, char *descrp, unsigned int kind, char *fmtp,
         char *labelp, char *namenextp);

DESCRIPTION
     Macros to wrap the sysctlinfo(4) interface to explore the sysctl tree and
     to get info about the nodes.  SYSCTLINFO() and SYSCLINFO_BYNAME() seek
     the node with id / idlevel or name, then the information specified by
     prop is copied into the buffer buf.  Before the call buflen gives the
     size of buf, after a successful call buflen gives the amount of data
     copied; the size of the info can be determined with the NULL argument for
     buf, the size will be returned in the location pointed to by buflen.  The
     value of prop[0] should be CTL_SYSCTL and prop[1] can specify the desired
     info, the possible values are listed later.

     SYSCTLINFO() accepts an array id of idlevel elements (between 1 and
     CTL_MAXNAME) and the following prop[1]:

     ENTRYFAKENAME
             if the node exists buf is set like a string with its name,
             otherwise sysctlinfo build a name depending on the id, e.g., with
             an id [1.1.100.500.1000] the name is &quot;kern.ostype.100.500.1000&quot;.

     ENTRYNAME, ENTRYDESC, ENTRYLABEL and ENTRYFMT
             set buf like a string with the name, description, label and
             format, respectively.

     ENTRYKIND
             sets buf like an unsigned int with the kind of the node, its
             format is: 3 bytes for flags and 1 byte for type, they are
             defined in &amp;lt;sys/sysctl.h&amp;gt;.

     ENTRYNEXTNODE and ENTRYNEXTLEAF
             buf is set like an integer array with the id of the next
             node/leaf of a Depth-First Traversal, the next level is &quot;buflen /
             sizeof(int)&quot; to be consistent with the acceptable level range.

     ENTRYALLINFO
             sets the buf with all the info of the node, it should be passed
             to the helper macro SYSCTLINFO_HELPER_ALL(), if description,
             format or label is NULL, descp, fmtp or labep is set to &quot;&quot;
             respectively.

     ENTRYALLINFO_WITHNEXTNODE and ENTRYALLINFO_WITHNEXTLEAF
             set all the info of the node like SYSCTLINFO_ALLINFO with the
             next node/leaf, buf should be passed to
             SYSCTLINFO_HELPER_ALLWITHNEXT(), if the node has not a next
             idnextlevel is set to 0.

     SYSCTLINFO_BYNAME() accepts the following prop[1]:

     ENTRYFAKEIDBYNAME and ENTRYIDBYNAME
             buf is set like an integer array with the id of the node, the
             level is &quot;buflen / sizeof(int)&quot;.  ENTRYFAKEIDBYNAME does not set
             the last level if its last level name is &quot;&quot;, e.g., &quot;n1.n2.n3.&quot;
             the id array is set to [1.2.3].

     ENTRYDESCBYNAME, ENTRYLABELBYNAME and ENTRYFMTBYNAME
             set buf like a string with the description, label and format
             respectively.

     ENTRYKINDBYNAME
             kind of an node, see ENTRYKIND.

     ENTRYALLINFOBYNAME
             sets the buf with all the info of the node, it should be passed
             to the helper macro SYSCTLINFO_HELPER_ALL(), if description,
             format or label is NULL, descp, fmtp or labep is set to &quot;&quot;
             respectively.

     ENTRYALLINFOBYNAME_WITHNEXTNODE and ENTRYALLINFOBYNAME_WITHNEXTLEAF
             set all the info of the node like SYSCTLINFO_ALLINFOBYNAME with
             the next node/leaf, buf should be passed to
             SYSCTLINFO_HELPER_ALLWITHNEXTNAME(), if the node has not a next
             node/leaf nextnamep is set to &quot;&quot;.

IMPLEMENTATION NOTES
     The kernel provides an undocumented interface for the info of the sysctl
     tree, obviously sysctlinfo and the kernel interface can coexist.

     In &quot;capability mode&quot;, see cap_enter(2), sysctlinfo checks if the node has
     the CTLFLAG_CAPRD or CTLFLAG_CAPWR flag before to return its info;
     sysctl(3) will check the &quot;capability permission&quot; to get or set a value.
     ENTRYFAKENAME has no capability check for compatibility with the kernel.
     ENTRYNEXTNODE and ENTRYNEXTLEAF check never the capability flags to
     traverse the tree also in capability mode.

     SYSCTLINFO() and SYSCTLINFO_BYNAME() seek the node with the id / idlevel
     or with the name then they share the same code.

RETURN VALUES
     The SYSCTLINFO() and SYSCTLINFO_BYNAME() functions return the value 0 if
     successful; otherwise the value -1 is returned and the global variable
     errno is set to indicate the error.

EXAMPLES
     If installed:
           /usr/local/share/examples/sysctlinfo/

     Example to visit the sysctl tree:

           int id[CTL_MAXNAME], *idp_unused, *idnextp;
           size_t idlevel, idnextlevel, buflen, i;
           char buf[BUFSIZE], *namep, *descrp, *fmtp, *labelp;
           unsigned int kind;
           int prop[2] = { CTL_SYSCTL, ENTRYALLINFO_WITHNEXTNODE };

           id[0]=0;
           idlevel=1;

           for (;;) {
                   for (i = 0; i &amp;lt; idlevel; i++)
                           printf(&quot;%d%c&quot;, id[i], i+1 &amp;lt; idlevel ? &apos;.&apos; : &apos;\n&apos;);

                   buflen = BUFSIZE;
                   if(SYSCTLINFO(id, idlevel, prop, buf, &amp;amp;buflen) != 0) {
                           err(1, &quot;ENTRYALLINFO_WITHNEXTNODE&quot;);

                   SYSCTLINFO_HELPER_ALLWITHNEXT(buf, idlevel, idp_unused, namep, descrp,
                                                 kind, fmtp, labelp, idnextlevel, idnextp);

                   printf(&quot;name: %s\n&quot;, namep);
                   printf(&quot;description: %s\n&quot;, descrp);
                   printf(&quot;label: %s\n&quot;, labelp);
                   printf(&quot;kind: %u\n&quot;, kind );
                   printf(&quot;flags: %u\n&quot;, kind &amp;amp; 0xfffffff0 );
                   printf(&quot;type: %u\n&quot;, kind &amp;amp; CTLTYPE );
                   printf(&quot;fmt: %s\n&quot;, fmtp);
                   printf(&quot;--------------------------------------\n&quot;);

                   if (idnextlevel &amp;lt; 1)
                           break;

                   memcpy(id, idnextp, idnextlevel * sizeof(int));
                   idlevel = idnextlevel;
           }

ERRORS
     The following errors may be reported:

     [ECAPMODE]         The node has not the CTLFLAG_CAPRD or CTLFLAG_CAPWR
                        flag in capability mode.

     [EINVAL]           name has more than CTL_MAXNAME levels.

     [EINVAL]           idlevel is either greater CTL_MAXNAME, equal to zero
                        or is not an integer.

     [ENAMETOOLONG]     name is &amp;gt;= MAXPATHLEN.

     [ENOATTR]          The node exists but its info is NULL.

     [ENOENT]           The node does not exist.

SEE ALSO
     cap_enter(2), sysctl(3), sysctlinfo(4)

HISTORY
     The sysctlinfo interface first appeared in FreeBSD 13.0.

AUTHORS
     The sysctlinfo interface was written by Alfonso S. Siciliano
     &amp;lt;alf.siciliano@gmail.com&amp;gt;

FreeBSD 13.0-CURRENT          September 20, 2019          FreeBSD 13.0-CURRENT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="bsd" /><summary type="html">sysctlinfo is an interface to explore the sysctl tree and to pass the properties of the nodes to the userland, this post displays the manuals (sysctlinfo.4 and sysctlinfo.3), for an introduction, examples and FAQ: http://gitlab.com/alfix/sysctlinfo.</summary></entry><entry><title type="html">sysctlview 1.0</title><link href="https://alfix.gitlab.io/bsd/2019/04/12/sysctlview-1-0.html" rel="alternate" type="text/html" title="sysctlview 1.0" /><published>2019-04-12T18:00:00+00:00</published><updated>2019-04-12T18:00:00+00:00</updated><id>https://alfix.gitlab.io/bsd/2019/04/12/sysctlview-1-0</id><content type="html" xml:base="https://alfix.gitlab.io/bsd/2019/04/12/sysctlview-1-0.html">&lt;p&gt;&lt;strong&gt;sysctlview 1.0 has been released!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;sysctlview is a graphical explorer for the sysctl MIB 
(&lt;a href=&quot;https://gitlab.com/alfix/sysctlview&quot;&gt;Source Code&lt;/a&gt; - 
&lt;a href=&quot;https://www.freshports.org/deskutils/sysctlview/&quot;&gt;Port&lt;/a&gt; -
&lt;a href=&quot;https://distrowatch.com/dwres-mobile.php?resource=showheadline&amp;amp;story=7880&quot;&gt;Distrowatch&lt;/a&gt; -
&lt;a href=&quot;https://discoverbsd.com/p/b762c40ece&quot;&gt;DiscoverBSD&lt;/a&gt;).
&lt;!--preview--&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/sysctlview1-0.png&quot; alt=&quot;sysctl 1.0 screenshot&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To install the port:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# cd /usr/ports/deskutils/sysctlview/ &amp;amp;&amp;amp; make install clean
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To add the package:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# pkg install sysctlview
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="bsd" /><summary type="html">sysctlview 1.0 has been released! sysctlview is a graphical explorer for the sysctl MIB (Source Code - Port - Distrowatch - DiscoverBSD).</summary></entry></feed>