svn commit: r327447 - head/sys/sys

John Baldwin jhb at freebsd.org
Fri Jan 19 18:20:21 UTC 2018


On Wednesday, January 17, 2018 03:14:37 PM Gleb Smirnoff wrote:
> On Tue, Jan 02, 2018 at 09:56:09AM -0800, John Baldwin wrote:
> J> > this is a recurring issue. Program that want to look into the 
> J> > internals of files such as mount.h
> J> > and define _KERNEL to allow themselves to do so.  It eventualy leads 
> J> > to all sorts of confusion and pollution.
> J> > Maybe we should make a policy on how to do this. At $JOB I had to hack 
> J> > it to define a
> J> > #ifdef _NOTREALLYKERNEL to split out parts we really wanted, but it 
> J> > would be better to have specific ones for
> J> > various specific 'rule breakers'..
> J> > e.g.
> J> > #if defined( _KERNEL ) || defined (WANT_TO_LOOK_AT_something)
> J> > 
> J> > kdump seems ot do the right thing with:
> J> > 
> J> > kdump/kdump.c:#define _WANT_KERNEL_ERRNO
> J> > errno.h:#if defined(_KERNEL) || defined(_WANT_KERNEL_ERRNO)
> J> 
> J> The past few years we have been using _WANT_FOO when new things need to be
> J> exposed and that is our current pattern.  However, that doesn't fix existing
> J> code for old things.
> 
> As one who added a lot of _WANT_FOOs, I must admit that I don't consider
> that a final and clean solution. But this seems to be a lesser evil when
> dealing with old code that has multiple dependencies.
> 
> New code needs to be written in a fashion that clearly separates kernel
> structures from user visible structures, so that no tricks with preprocessor
> are needed.

The problem is that some kernel things aren't generically useful for userland
and really should be opt-in, e.g. the negative errno values _WANT_KERNEL_ERRNO
protects that only the kernel uses and very few things in userland should see.
We will always have some system tools that are bound to the kernel that will
need to understand certain kernel internals that the vast majority of userland
programs will not / should not need.

-- 
John Baldwin


More information about the svn-src-head mailing list