From nobody Sat Oct 5 07:11:27 2024 X-Original-To: dev-commits-src-branches@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 4XLGmb6Dxpz5XrVB; Sat, 05 Oct 2024 07:11:27 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XLGmb4R6qz4NQp; Sat, 5 Oct 2024 07:11:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728112287; 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=ciE7+qpZ40fYjwJAkNgfOt1SCq+jOEA1x/G965FyEsk=; b=E718+EVaextippSd+xWNcP8N5b9Xl0tKYQbKoSYXHxFQkRC+gs+89Gsk2OXwWyrHfbXZ9V CHnC1vvmgy4cTxZsxQgMnmXdyiGT5g/a7/YByhVtkoRtHxrpLQ3A/+zqIRv2KgnX7QjKe1 oDUaFY5dEBfFTGCoRI2QBstpA+ZwiOEaG/9xZ+5XgWjieR5n1u4uiDYHARC6kJ+r7ta1KR S/COadMQBL8FMJZUesRiszQV/ipvo0gOfnh8uTlIxawbJI/EHTlqIkgJ4lFI7oYv8dvKZY V73IjKlRj7dmJeLC3NHEmeIKzcxlnC4FBqkiAzq9jbgsesx+sr+0Pg60Kuw7/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728112287; 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=ciE7+qpZ40fYjwJAkNgfOt1SCq+jOEA1x/G965FyEsk=; b=lvr/0R+L4NnApM33h1qAa8fIlzGeIkW7qs52sfDGfP8W/nP3h30o3/SsMG+8lZhMsJGKp7 3p3dnu/C74KYmxNyonDJXYYlG/CTQGHyw4zXdwYJMD5tq2teqJFIpJA/sn5GcZPPkageL7 /Bti9NMnmmLr2WSnRN6K2vBdBbLx7SSoNTyapE47MYUiKTRrzcvbbmJ6Uvml129ONMMU/o oZOtWetNPgD2P1GgveDvl+ZNnQesWGqkCjCoFElpOWM9oSUYrTkEtHh84vE4eypoemPpJg x4yL2uqKuOV+7enzZrDXuSK3oyN1bunxx/nn+QMQ+9TaLmf1KJ9SjPYGHnH15g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728112287; a=rsa-sha256; cv=none; b=MgolJv/w3TMPm83u92uGSKiXnAw/ZY7kEGYeJwA8m0++arz5wSKw0WjmB6KkRJgvjtshWk FW6IhBi8B9sarMW0KNSlqghNxyxyMhSNzIDBj5gWMb1MJHTJZYI0fXnlUKCuTjKF5bA/pC sm1FqhKIiFtpEi1xt+2ikMjGFk9S4jmK6dtOV2EH/1hsm2y8pJTY4ZfLoMOvAA3Xh5DIhW UfMw6rXcdcizQdQkMtIz0OWz0MgKJ7GpMOuiMdqYD5D0QRH6aeRN2UNTZG51yPyuhy66gD etJS4iwotzHG4On+jhWa9YPFbEcRTFIneeembFpTjwbNFcAK2XXoIc+fwsZm0A== 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 4XLGmb42vyz17mC; Sat, 5 Oct 2024 07:11:27 +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 4957BRwg001546; Sat, 5 Oct 2024 07:11:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4957BRMN001543; Sat, 5 Oct 2024 07:11:27 GMT (envelope-from git) Date: Sat, 5 Oct 2024 07:11:27 GMT Message-Id: <202410050711.4957BRMN001543@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: d9aa256201b8 - stable/14 - sysctl: add KERN_PROC_RLIMIT_USAGE List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: d9aa256201b8d149907d490029d5a3ea123a3d89 Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=d9aa256201b8d149907d490029d5a3ea123a3d89 commit d9aa256201b8d149907d490029d5a3ea123a3d89 Author: Konstantin Belousov AuthorDate: 2024-09-22 17:01:56 +0000 Commit: Konstantin Belousov CommitDate: 2024-10-05 07:08:56 +0000 sysctl: add KERN_PROC_RLIMIT_USAGE (cherry picked from commit c85d3064c454bde9f1c0cfbb6f42c0ac9fa229e9) --- sys/kern/kern_resource.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ sys/sys/sysctl.h | 1 + 2 files changed, 51 insertions(+) diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index b4548b38f633..9729bf987aa6 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -1744,3 +1744,53 @@ chgpipecnt(struct uidinfo *uip, int diff, rlim_t max) return (chglimit(uip, &uip->ui_pipecnt, diff, max, "pipecnt")); } + +static int +sysctl_kern_proc_rlimit_usage(SYSCTL_HANDLER_ARGS) +{ + rlim_t resval[RLIM_NLIMITS]; + struct proc *p; + size_t len; + int error, *name, i; + + name = (int *)arg1; + if ((u_int)arg2 != 1 && (u_int)arg2 != 2) + return (EINVAL); + if (req->newptr != NULL) + return (EINVAL); + + error = pget((pid_t)name[0], PGET_WANTREAD, &p); + if (error != 0) + return (error); + + if ((u_int)arg2 == 1) { + len = sizeof(resval); + memset(resval, 0, sizeof(resval)); + for (i = 0; i < RLIM_NLIMITS; i++) { + error = getrlimitusage_one(p, (unsigned)i, 0, + &resval[i]); + if (error == ENXIO) { + resval[i] = -1; + error = 0; + } else if (error != 0) { + break; + } + } + } else { + len = sizeof(resval[0]); + error = getrlimitusage_one(p, (unsigned)name[1], 0, + &resval[0]); + if (error == ENXIO) { + resval[0] = -1; + error = 0; + } + } + if (error == 0) + error = SYSCTL_OUT(req, resval, len); + PRELE(p); + return (error); +} +static SYSCTL_NODE(_kern_proc, KERN_PROC_RLIMIT_USAGE, rlimit_usage, + CTLFLAG_RD | CTLFLAG_ANYBODY | CTLFLAG_MPSAFE, + sysctl_kern_proc_rlimit_usage, + "Process limited resources usage info"); diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 0cfa2a7bd245..a446d6701cfa 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1042,6 +1042,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); #define KERN_PROC_NFDS 43 /* number of open file descriptors */ #define KERN_PROC_SIGFASTBLK 44 /* address of fastsigblk magic word */ #define KERN_PROC_VM_LAYOUT 45 /* virtual address space layout info */ +#define KERN_PROC_RLIMIT_USAGE 46 /* array of rlim_t */ /* * KERN_IPC identifiers