From nobody Fri Apr 11 18:42:59 2025 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 4ZZ5Cm010Wz5sTmw; Fri, 11 Apr 2025 18:43:00 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZZ5Cl6ZWwz3bLm; Fri, 11 Apr 2025 18:42:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744396979; 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=h8o3cmSgWSpVO82OOtlfHaDf5o5Rc/sDMlB5cFcIflo=; b=KFgm9AUHZ6WtK6l0dIHSvg6/9KINWbgJiKaRYnF6bQpQgvs5uhILPEKIuIc3QwG5+2uP+Y NbgD/ntEXhJxG/v9JT7IG2eYOkTMHSkXSB+Zp+wlgV9HoualO879zOJ9docAhb5hqJ8k/n uvxWAPXK+dA6q6CKjRoyiNLMmrtR+AgiDeKxuknGiw9XSEK6YS4sBRQV1oHkhC+JYRjupj SH+6asp6Ba1S0H962B/gHb6z4NyRur3Xz0L9bak70Aa2qnIRmVauKDFwZB/Qg38CWPiJK7 zTPFBofqvxbMIr5iGAxXbXgGWJTwAXX98Oqtnp+qr7fguaUxQCtLRkfKCalU7g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1744396979; a=rsa-sha256; cv=none; b=NYx+/DNVJolQ6T29WUBgaXL5M87i0pTdLeqFXYdBSwl+XN+BSeWFYjhi0E/F0KbBIsLaiv EdassgD3NiRcEm483uxUEs/WznJmSE2I5w7F2dCqOYM03gKwW+Zkk8Mv6iw3v/R3/8Ej32 2hkx/IM9LYHTu0Xgg8DxK7d6cZlXUJ4hP29rC3l5FmCFslKF+jfWqnG2KsnbH9uO4NVgN0 6VfoYpr4mGhLbuxORPJ60COS4aSgXtvBKTYAfDTtyKq3lH1RqE3emaEqteMAOomfdRtKfS 5mHsSz1MoCkN+Ulh3dNjkDneosbswY1qZlfcNAoK6dlfwS2k/C2PQMWTdx8jZQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744396979; 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=h8o3cmSgWSpVO82OOtlfHaDf5o5Rc/sDMlB5cFcIflo=; b=fVQx12XIDJnkSazdz2gscmIIxwfOdYA6V5cQw1wSiqQZZZlLAyhOgEKXMyzeNFsJBb+hMe dRVUF6JJREZ4F2AEU6Qj09ffuPDkmRkx3pOPeHUq3rnIwFprElaJVP2tmmMmeLibclObaJ rtXgjnOs080I0FUtwEs9v6hMqwysa/CCizzh3ldsqUkdKW7WtTx6rZGwMQcEwKFwtpIVoC 6K5sPDweyV5/wvRAhAelp8eHdDwiZQcYSkNbNrdlSJt6ndm0VqDKjSuomXSlaEUB5o9TTQ einKWEx02X+KaYeK3wDFFc1aB1CgQhrytcD6q6PP3UJ4EsEE8gP7m08fmrM6DA== 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 4ZZ5Cl69ZtzlPw; Fri, 11 Apr 2025 18:42:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53BIgx2w077126; Fri, 11 Apr 2025 18:42:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53BIgxMK077123; Fri, 11 Apr 2025 18:42:59 GMT (envelope-from git) Date: Fri, 11 Apr 2025 18:42:59 GMT Message-Id: <202504111842.53BIgxMK077123@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: 4b60fac3a5c7 - main - kinfo_getfile: Add a comment explaining 4/3 ratio 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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/main X-Git-Reftype: branch X-Git-Commit: 4b60fac3a5c7a53f6d1a4480f37eb906bbacf21b Auto-Submitted: auto-generated The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=4b60fac3a5c7a53f6d1a4480f37eb906bbacf21b commit 4b60fac3a5c7a53f6d1a4480f37eb906bbacf21b Author: Ed Maste AuthorDate: 2025-04-11 18:37:39 +0000 Commit: Ed Maste CommitDate: 2025-04-11 18:42:44 +0000 kinfo_getfile: Add a comment explaining 4/3 ratio We first get the expected size of the data from the kern.proc.filedesc sysctl, allocate 4/3 of that size, and then fetch the data. Add a comment about the reason (the fd table may grow between the two calls). Sponsored by: The FreeBSD Foundation --- lib/libutil/kinfo_getfile.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/libutil/kinfo_getfile.c b/lib/libutil/kinfo_getfile.c index f1441bdf771a..345da657df81 100644 --- a/lib/libutil/kinfo_getfile.c +++ b/lib/libutil/kinfo_getfile.c @@ -27,6 +27,10 @@ kinfo_getfile(pid_t pid, int *cntp) error = sysctl(mib, nitems(mib), NULL, &len, NULL, 0); if (error) return (NULL); + /* + * Add extra space as the table may grow between requesting the size + * and fetching the data. + */ len = len * 4 / 3; buf = malloc(len); if (buf == NULL)