Querying kernel features

Kristof Provost kp at FreeBSD.org
Fri Jun 19 17:47:10 UTC 2020


On 19 Jun 2020, at 1:19, John-Mark Gurney wrote:
> Kristof Provost wrote this message on Thu, Jun 18, 2020 at 22:57 
> +0200:
>> Say that I have a test for an optional kernel feature (say ALTQ, or
>> TMPFS) is there an elegant way of figuring out at runtime if it???s
>> available?
>>
>> Doing `sysctl kern.conftxt | grep ALTQ` feels a little inelegant, and 
>> is
>> begging for issues with incorrect matches.
>>
>> I???m tempted to add a sysctl node for ALTQ, but perhaps there???s a
>> better way. Or perhaps this should be a general feature (so we???d 
>> have
>> nodes like kernel.feature.tmpfs=1).
>
> Look at kern.features...  There's a FEATURE macro to add entries to
> that, but looks like there isn't any man page for it...
>
> sys/geom/eli/g_eli.c:FEATURE(geom_eli, "GEOM crypto module");
>
Ah, thanks, that’s pretty much exactly what I was looking for.

There is a man page for feature_present(3), which is a C function to 
check for the presence of a given feature. It does the sysctl for you.
That’s not quite what I need (atf-sh make sysctl the easiest 
interface), but I figured I’d point out at least something is 
documented.

Best regards,
Kristof


More information about the freebsd-testing mailing list