Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 03 Jan 2008 17:59:57 -0800
From:      Julian Elischer <julian@elischer.org>
To:        arch@freebsd.org
Subject:   RFC: sysctl additional functions/macros
Message-ID:  <477D931D.4000303@elischer.org>

next in thread | raw e-mail | index | archive | help
I would like to extend the current SYSCTL_INT() with 
SYSCTL_INT_CLAMPED() or similar, where you also supply a
maximum acceptable value. (and maybe a clue as to what to say if it is 
a bad value).

so many users of SYSCTL_INT don't check for bad values because it's so
much harder (you need to supply your own handler), and so many
simple handlers exist fo rthe people that DO check that it seems to
me that we should provide a pre-canned way to do this....

we are limited to using the existing structure,
but as we have no existing callers we can redefine
one element....

I would suggest:

I'd like to test for a minimum too but I think I can only squeeze one 
field out of the existing struct sysctl_oid.

SYSCTL_INT_CLAMPED(parent, nbr, name, access, ptr, max, descr)
                                                   ^^^^

anyone think it's a bad idea?
After all the macros are evaluated, (etc.) it would call:
( off the top of my head )

int
sysctl_handle_int_max(SYSCTL_HANDLER_ARGS)
         {
         int  error = 0;

         error = SYSCTL_OUT(req, arg1, sizeof(int));

         if (error || !req->newptr)
                 return (error);

         if (*(int *)arg1 > (int)arg2)
                 error = EDOOFUS;
         else
                 error = SYSCTL_IN(req, arg1, sizeof(int));
         return (error);
}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?477D931D.4000303>