From nobody Fri Sep 27 15:03:30 2024 X-Original-To: dev-commits-src-main@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 4XFYcz0c29z5Y6DS; Fri, 27 Sep 2024 15:03:31 +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 4XFYcy52f3z58fK; Fri, 27 Sep 2024 15:03:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727449410; 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=eRLqVwoP4dHTYrz5e/nK8ud3whTnrkSAiPomW6ZTTcs=; b=NxjZYtajUI1dNI3qoy7Tw+Mb0FPvMSJ6jusRTM/O73HU65B6a6GCn+W6GHb+6LEgg45VX2 xj4koY5TbGjdtqTH2JHXaVAAS0ldb+ppObaJRv84LMJFY0NgNc9mkOMdJaSQuJodInaM/5 xXDYzuhCslNRo9ksf9dXCWlsCaEytnIERAMQ1gCsj5q9FxbHaP8vYj8yZ8LQ0T9TW4tQNw J4EaK5Ttwjrt7P/uWIpDB2xS889dYHnaJyqYNFzrM0vhaGqRJV1y4Y1PLkiTf/wFOho09A MpyyLh2ix7uVuYhiyb7XEaZ8FBt/C3BnoIy0E8zUVmmto5btqoTZZHPl38Ryhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727449410; 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=eRLqVwoP4dHTYrz5e/nK8ud3whTnrkSAiPomW6ZTTcs=; b=oabj8WViRJBjIbAOlJ8FoLKaXIexxlvevGNNSzk0DiYApFk2iRQiIAS5KJl9XYK5AbZU/W Q6xU4YaUIeYDp0pgjZKIi7kBK6xK2KUVaFIf78Nw8Oitq0JtSRv7UiI1tsK6hMNUUus73G MsxUz4izn/OT22Zuki13D59lTUbxBBDfZ0aPU1ayKf7SSDe62jzCYgKmcjwp+VCsDpCREs YiaBKSiQU6ku3G7i9ZyAAY+BTI7c6tPUAZraICz9VBYZrtIXNfsb7+qjPMJx1Ws0ejynYl yaKgKdrewEJep9OIMROInY100lmuexiFjDy4OQNuretudGNOUSCvYI6wJdjibQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1727449410; a=rsa-sha256; cv=none; b=ExcWJxjCI2HaXOSlk3XBkvlzn8HTz2dxzW2th2ify4YQdvcSBGMgqvTlufSXxJxLzAaIp/ ne02xtb8nU3WAloJp1DhHvPcx8WOngJrcUyv9dZ21Cu/uggkmacI9Hwdh8mM/nAPAXBquD ZrEgjFSHxyU18PrX1hgaKZzsmuAE0qIeahQoXGmnwVJ2GYm4Pl9r9RYCcBmFZBVRnnlbxx NLKfq0TtSK2pnDfrxQ464NwxHO8EKsofhscj9shfRkV2r8eCh1H1lcdoB5cM1XLrKczdqI /6KznM4bZKlr9Of+2UF6lJSInugnvbReWPqX/LdIjtAKHnHlkj34OSMjHXZ2ZQ== 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 4XFYcy4Tstzlqr; Fri, 27 Sep 2024 15:03:30 +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 48RF3UO6009246; Fri, 27 Sep 2024 15:03:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48RF3UjC009243; Fri, 27 Sep 2024 15:03:30 GMT (envelope-from git) Date: Fri, 27 Sep 2024 15:03:30 GMT Message-Id: <202409271503.48RF3UjC009243@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: c85d3064c454 - main - sysctl: add KERN_PROC_RLIMIT_USAGE List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: c85d3064c454bde9f1c0cfbb6f42c0ac9fa229e9 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=c85d3064c454bde9f1c0cfbb6f42c0ac9fa229e9 commit c85d3064c454bde9f1c0cfbb6f42c0ac9fa229e9 Author: Konstantin Belousov AuthorDate: 2024-09-22 17:01:56 +0000 Commit: Konstantin Belousov CommitDate: 2024-09-27 15:02:23 +0000 sysctl: add KERN_PROC_RLIMIT_USAGE Reviewed by: markj, olce Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D46747 --- 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 db5cce833012..c8b01afeab4f 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -1741,3 +1741,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 66c6ff1640b7..f7abc27083aa 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1040,6 +1040,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