From nobody Wed Feb 09 22:10:42 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id AEBF619A396B; Wed, 9 Feb 2022 22:10:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JvDbQ4PBzz3L2V; Wed, 9 Feb 2022 22:10:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644444642; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dIkjpzt1nTxWCYduyFPgxd9ZdvutS7FWoD+joEYlnqs=; b=L9W+p22inMjL3epvokXm0cz/kMterW9omTyvq7qGf435gGOWNzFU6GOu4P71v9tI1eSV1W j8b3qk48SJT15887vUn6jQuvqMltmWYWvbYbMp3Jevv/YyBfhQ1ClAvxFjBPaZhjmZg9hE 9Ev3Lvjl+xVPlzfCmZLc3A9qsBO1DVPSJzZ5c8qw3goYhZ4F4otQR9ZE3D8B/z/UFNTUZL I0ZlDEkz8isExDSobZGywtuBvPtwrZtOcQpbbbJHJ09SMvahbbEUG+gHtY/NdvRDPclEhY VFd9AKzEVzYqWmBhoJL3TwmjSq65igN/sKF2ir3u/cIShjy/AC5l6OVEYuTYYA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7788A14F6E; Wed, 9 Feb 2022 22:10:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 219MAgpQ006224; Wed, 9 Feb 2022 22:10:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 219MAgdu006223; Wed, 9 Feb 2022 22:10:42 GMT (envelope-from git) Date: Wed, 9 Feb 2022 22:10:42 GMT Message-Id: <202202092210.219MAgdu006223@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Stefan E=C3=9Fer?= Subject: git: af7d105379a6 - main - sysctlbyname(): restore access to user variables List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: se X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: af7d105379a649b7af4bffd15fbeab692bb52b69 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644444642; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=dIkjpzt1nTxWCYduyFPgxd9ZdvutS7FWoD+joEYlnqs=; b=kWOVXkzVDFv33j3aQ8BudLGSfiGDQveh8jbWq4j2Q77IMM70VmU6GQ2J91ERAScUJa9JQm RYDwtvVxXitIX/CilnlgCplgirho1OZgneN+BJwhn7OML9rlh4NgCjE5rY539WCJrSImmf ID0X26HAZ/kAHghJOxDACD60+71jSw+dgqXesM5pxhjFl6tBlQFNkaaPXGtxHIHGAz4rQO ElP6/QI5ngH5W4ZjyFxldon+lH/tqYZUmF4BMRW0juuAfETSQTPH5YK3zDwRrB0wkvJYnA yZ5D8zZRb7LBvGYhP0XTceOM55MJa6mTVG+o35mhSRH7P3F1Tq7rboVPQ3yj+A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644444642; a=rsa-sha256; cv=none; b=QbztGDRhBRB0shGFOXZ7vHKrXzBWIl8ZIqSVLdrVQu74AD3AQORRLIiqVt/VdjEk6qLlnq J8R9FTs4u+2r8gdoiri1sOG0EK7VZSGJ//wNAoCrBwZPgy/0nMcAqibMyXnUGdfWE0OTKn nYfuzbJqtUI1k7hkF8VVrhkSctsfPe0kBeRkLB4xSzkDFi511xSo8r9NddFL2n5oLsi4fo fcybVOF7bRSj3sjQKc7Sl+qdIc/LmMOKXenIIyAA9OrFeHfzjyGryCbtgXvjVV0xNINLJE ntaWstt70z1uCAB9wrF5bhF6ggfdnd74hJJmKnjtMHTYQfjaOHSirb9ZWRx4rg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by se: URL: https://cgit.FreeBSD.org/src/commit/?id=af7d105379a649b7af4bffd15fbeab692bb52b69 commit af7d105379a649b7af4bffd15fbeab692bb52b69 Author: Stefan Eßer AuthorDate: 2022-02-09 21:56:00 +0000 Commit: Stefan Eßer CommitDate: 2022-02-09 22:10:31 +0000 sysctlbyname(): restore access to user variables The optimization of sysctlbyname() in commit d05b53e0baee7 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 --- lib/libc/gen/sysctlbyname.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/libc/gen/sysctlbyname.c b/lib/libc/gen/sysctlbyname.c index 9b4ffc0ca4ae..5086cc4b7d81 100644 --- a/lib/libc/gen/sysctlbyname.c +++ b/lib/libc/gen/sysctlbyname.c @@ -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)); + } }