sysctlbyname(): restore access to user variables

The optimization of sysctlbyname() in commit d05b53e0ba had the
side-effect of not going through the fix-up for the user.* variables
in the previously called sysctl() function.

This lead to 0 or an empty strings being returned by sysctlbyname()
for all user.* variables.

An alternate implementation would store the user variables in the
kernel during system start-up. That would allow to remove the fix-up
code in the C library that is currently required to provide the actual
values.

This update restores the previous code path for the user.* variables
and keeps the performance optimization intact for all other variables.

Approved by:	mjg
Reviewed by:	kaktus
Differential Revision:	https://reviews.freebsd.org/D34171
This commit is contained in:
Stefan Eßer 2022-02-09 22:56:00 +01:00
parent 489d7a8528
commit af7d105379

View File

@ -41,8 +41,17 @@ sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
const void *newp, size_t newlen)
{
size_t len;
int oid[2];
len = strlen(name);
return (__sysctlbyname(name, len, oldp, oldlenp, newp,
newlen));
if (__predict_true(strncmp(name, "user.", 5) != 0)) {
len = strlen(name);
return (__sysctlbyname(name, len, oldp, oldlenp, newp,
newlen));
} else {
len = nitems(oid);
if (sysctlnametomib(name, oid, &len) == -1)
return (-1);
return (sysctl(oid, (u_int)len, oldp, oldlenp, newp,
newlen));
}
}