From nobody Mon May 16 12:28:37 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 8A0181AE393B; Mon, 16 May 2022 12:28:37 +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 4L1z7T3THwz4kWx; Mon, 16 May 2022 12:28:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652704117; 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=19FeHxObImN9ls4oMQVmmumcJAUQuu+Aw5QCSFW1+dw=; b=eCeCjjEKTunAT1rZG4nvKmtoKAA756pvcvNRWCyJWrqunrvSVeh+2Ees/kEnLsJdsPzdGJ vxFqomSS2f77CF14oRO6TwIHrv3BBQv/xiVsxqctR9KIfsfPvpfC7wVoik/KUGutEgiis3 GUSkCeLuueZNBdjC5dvuBz+p0WL1Aof40OhhOWvqvZe9tE+hO2mG9q3MmVjhTsX3JH7p3M H2dQMZc2Svlj3o1dSJVu8bVveumd05GNdAJkf9VTbef8pySYSpT/IBKYT5SYU91Zsc1mGr eQLUrambdJnFxCcO6j2MzI6F+Ik01udYEg0uMYDUs1L8JudEJ28D8hMKpXiMJQ== 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 57B5220206; Mon, 16 May 2022 12:28:37 +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 24GCSbLT061940; Mon, 16 May 2022 12:28:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24GCSbOP061939; Mon, 16 May 2022 12:28:37 GMT (envelope-from git) Date: Mon, 16 May 2022 12:28:37 GMT Message-Id: <202205161228.24GCSbOP061939@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 72bcf2fe9041 - stable/13 - libutil: eliminate one syscall from kinfo_getproc 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: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 72bcf2fe904113e8b2e9d8af71fdf62c491b144a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652704117; 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=19FeHxObImN9ls4oMQVmmumcJAUQuu+Aw5QCSFW1+dw=; b=CcRJUekJtAVbQ8tLGQW1LgtIPzgS9TC1KgJBnZPGrZe8tdITu6nBBMye67AAS1CgK4+U9b OOTjFrcs2vUoC7wpVWQ2g3Duk/vaaLpqG1LozPCyS8pyxX6A/zIIg2FusoGS3v4k8tFeVy vSQcz4oO50BLFLO+pEkTmBgMwSRmeXI3dv5V5JZfNaZjtjT5S7YJ6Gfz+JDfGGVlRHv5oX Sq/VmpaKf2u/Ye9IMbIaPAgNtvnMJGiSyzcaFKGnh/4VhMKdFN7HFQfsPDTMUi4VzdpYbt ICQZxDlLWm4dcaZ3eRLqi4y5qIMkxDYGd8OZr8FJI1dyRpai8mffZ3UdDKTfEg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652704117; a=rsa-sha256; cv=none; b=viQlpbKgjmp7HjJ8EBC8Kj/DpeCZ79yHeX36rtvtMdc5ZQ1fWru/CIREfVFZGssia9hai0 pCgFOrPK0mxJgLQ8J2lNg3V3kCx9/j3NK51st7LVM18u3WZnVI7FzHmMugvyQbgbr2tKGI xb2LFmJkDLVAljGlQmxz/SJ6pMZqesVX8LmedVCIGO551Up1KtIdY/t7Om6xpWfMTHgyN9 GaL+7NZhdQR3Z9sO4MgxuBH5uFuuwpDU8CO7b42xj3lWAKZtLgDbM72WNt33MzCDaADXnt QsePN85t2tSxy93FLdFdRdmH2B0cJGUUy1cudnq7JNCUiLzqvBBApOiqx0lqKg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=72bcf2fe904113e8b2e9d8af71fdf62c491b144a commit 72bcf2fe904113e8b2e9d8af71fdf62c491b144a Author: Ed Maste AuthorDate: 2022-05-06 16:41:04 +0000 Commit: Ed Maste CommitDate: 2022-05-16 12:28:24 +0000 libutil: eliminate one syscall from kinfo_getproc Previously we invoked the sysctl with a NULL buffer to query the size, allocated a buffer, then invoked it again to fetch the data. As we only handle the case where the sysctl provides data of the expected size we can just allocate a correctly-sized buffer to begin with. Reported by: Thomas Hurst via Twitter Reviewed by: kevans MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35140 (cherry picked from commit 904c148f1c939f080b9fad345b76caa8ccb6d03c) --- lib/libutil/kinfo_getproc.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/libutil/kinfo_getproc.c b/lib/libutil/kinfo_getproc.c index 4d16b1c16a13..e34fdbdf18e8 100644 --- a/lib/libutil/kinfo_getproc.c +++ b/lib/libutil/kinfo_getproc.c @@ -46,17 +46,15 @@ kinfo_getproc(pid_t pid) int mib[4]; size_t len; - len = 0; + len = sizeof(*kipp); + kipp = malloc(len); + if (kipp == NULL) + return (NULL); + mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PID; mib[3] = pid; - if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) < 0) - return (NULL); - - kipp = malloc(len); - if (kipp == NULL) - return (NULL); if (sysctl(mib, nitems(mib), kipp, &len, NULL, 0) < 0) goto bad;