Bug 243532 - kern.ipc.maxsockets wrong init value
Summary: kern.ipc.maxsockets wrong init value
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
Depends on:
Reported: 2020-01-23 00:10 UTC by rozhuk.im
Modified: 2020-01-23 06:49 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description rozhuk.im 2020-01-23 00:10:22 UTC
I got:
kern.ipc.maxsockets: 517552
kern.maxfiles: 262144

static void
init_maxsockets(void *ignored)

	TUNABLE_INT_FETCH("kern.ipc.maxsockets", &maxsockets);
	maxsockets = imax(maxsockets, maxfiles);
SYSINIT(param, SI_SUB_TUNABLES, SI_ORDER_ANY, init_maxsockets, NULL);

looks like imin() should be used instead of imax():
	int error, newmaxsockets;

	newmaxsockets = maxsockets;
	error = sysctl_handle_int(oidp, &newmaxsockets, 0, req);
	if (error == 0 && req->newptr) {
		if (newmaxsockets > maxsockets &&
		    newmaxsockets <= maxfiles) {
			maxsockets = newmaxsockets;
		} else
			error = EINVAL;

Also, IMHO sysctl_maxsockets() (and some other sysctl val handlers) should not return EINVAL in case: oldval == newval.
This will avoid multiple error generation on system boot in case sysctl.conf contains kern.ipc.maxsockets, kern.maxfiles and other things that could not be decreased.