Solved [solved] Understanding __FreeBSD_version

Greetings!

I was not entirely sure whether to post this under general or development; if it warrants a move to the development section please let me know.

I am trying to better understand how to differentiate versions of FreeBSD while working with a configuration management system, Chef in particular. Besides the major, minor and patch levels of a FreeBSD release (e.g. 8.2-RELEASE-p2) there is __FreeBSD_version. As far as I can currently tell, you can read this value off the header file /usr/src/sys/sys/param.h.

In practice a machine may or may not have sources on it. And of course even when a machine has sources there is still the caveat of when sources have been updated and the system has not been rebuilt yet; reading off file here may give an incorrect value if __FreeBSD_version has changed. uname unfortunately does not provide this value although it does provide the repository commit/revision number.

Is there a way of consistently and correctly detecting __FreeBSD_version on a running FreeBSD system whether or not sources are available on the machine?
 
Re: Understanding __FreeBSD_version

/usr/ports/Mk/bsd.port.mk first looks for param.h. If not found, it uses sysctl -n kern.osreldate.
 
Re: Understanding __FreeBSD_version

neolix said:
As far as I can currently tell, you can read this value off the header file /usr/src/sys/sys/param.h.
Sure, but don't forget that the source tree eventually builds your system. Some parts can only be accessed in the source tree itself, but this does not apply to the headerfiles. Well, not all of them.

So in this case you should check for this header file on the system itself. You'll find it under /usr/include/sys.
 
Re: Understanding __FreeBSD_version

Perfect! Thank you @wblock and @ShelLuser. That's all I need for a well rounded solution.
 
Last edited by a moderator:
That may be a good way to check for the version. If you use freebsd-update(8) the kernel may not get updated (because the issue wasn't in the kernel) so the kernel version may not be the correct one.
 
Back
Top