these functions exclusively return (0) and (1), so convert them to bool
We also convert some networking related jail functions from int to bool
some of which were returning an error that was never used.
freebsd_igalic.co on Apr 8 2021, 8:00 PM.Authored by
Yeah, I'd been meaning to get around to that ;-).
While you're at it, you could add prison_flag() and prison_allow(). prison_flag() currently returns either 0 or the flag passed in (converted from unsigned to int), but is only ever used by callers as a boolean and should become one for clarity. I was probably being lazy/micro-optimizing when I wrote it.
And then there's netinet/in_jail.c and netinet6/in6_jail.c, which have prison_restrict_ip() and prison_equal_ip(), . They also have prison_saddrsel_ip() which are funny bool/errno hybrids that can return 0, 1, or EAFNOSUPPORT, but whose callers only ever use the result as a bool (i.e. EAFNOSUPPORT is equivalent to true); that may or may not be better served as an actual boolean.
I've been meaning to submit this patch since i first read thru this file
aye, will convert those too
there are other candidates that return (0) or a single error that is always the same, but here we would need modifying the call-site :
I think anything like should remain as is. While they may only return one possible error, they usually called with the typical errno usage:
error = prison_foo(...); if (error != 0) return (error);
I wouldn't want the callers to have to worry about what error they should be reporting when my function fails.