From nobody Fri Sep 27 15:03:31 2024 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 4XFYcz6yJJz5Y5rK; 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 4XFYcz5W4Pz5966; Fri, 27 Sep 2024 15:03:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727449411; 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=Vbe4QCsYOcq8xMgWtiqtL45ny3ofo5b9Ta1i3Fdn6kc=; b=UtoQ26rMrR32xs7NWhcT+jOrAE8wxuLz9lwk23BXldOX+rA2lNWcEVdBh1Afr5+jwD99tH pXE27r7jQ332nzy+fp/93C5eOshcQwGkZBULHMpdQgw+YFMeCo0jrUYP1ZoQYEC5f4pD/a X//j682r/bBawOT/u6XOaaMGQSQe9acZogowCLFc7X6XznwztMDxZXio40L7eMnUyZTTca CSA1HrNdNnS+3wYVWruAWmhdArfKaxuVLS1o0a0RmScr5oPnhRJOcSuPvowqUkGsxIMHVJ r1xr+BIYOe0AS+ZPA0Jq3yChYyZdEWL+9D7Tw28qsYLuTDpaCXEln2+Ujy2d6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727449411; 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=Vbe4QCsYOcq8xMgWtiqtL45ny3ofo5b9Ta1i3Fdn6kc=; b=e5BnWIFfo3xRnT4s1a2u1AevbC2ZJRe+kimPlf3H9SWnuUkTrkUmrkPv/zeXQKXNjy8tmv SyXeYBa8T/P4PR2EasnEbWP6AhskPN6HUxhvawqABwVkQoFtb1FZXYA5zU26P6zjzWrNu2 2PRhI9dfEG09NgWTlQwtYc1tOUah0uW52xNiVOr/VB9psORz3oeOwAnObjIwbnng/rD63g Xd7Z3re4SNPCZmPOtiXwV64IIuqsd9Py+wU3+JurMXmGZDirxYmei6PDBT0Mg006ti1IkP +Ev6VSnyDa7xFSMu6V5rdnFLOejNYEpiEsGMbqj8/wMN25x/DOLtO9q5kgxi3A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1727449411; a=rsa-sha256; cv=none; b=T1j1THHOk1zonI8ras1vSM+dOJqurlmXWNPKFWLvvGPozexc9rpYMjqN7NmtBD0Kc+b7pE zSS/y3fd7Emnk1Ez2/oaKs+Md2yZRVxf3n3sBNj1N9u586P4RNpEGWKifDZW4nJD2soygU Lc6kbmFzafgHXeIlKN7GgwdO5UMNjkScW55U1qqd7qM3xAMKlGoV2gSe8WY1NFSXH1bHDb M22LSuQ464SAcc80tZOdVBktdz0RWaopPffUvgtSwQ/Bt+Aesq2phRINe8nZZFaBGCWFwI 5e3f2hmTJsTtm6382J4MNFPIxk3vVcj0x1O1pLfxgqzhcXutuyQ/R+e+eih9xw== 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 4XFYcz579SzlWy; Fri, 27 Sep 2024 15:03:31 +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 48RF3VTV009287; Fri, 27 Sep 2024 15:03:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48RF3VIY009284; Fri, 27 Sep 2024 15:03:31 GMT (envelope-from git) Date: Fri, 27 Sep 2024 15:03:31 GMT Message-Id: <202409271503.48RF3VIY009284@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: 6126f4ea646a - main - libprocstat: add procstat_getrlimitusage() 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6126f4ea646a3c19647c3efdcf672641cff6954b Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=6126f4ea646a3c19647c3efdcf672641cff6954b commit 6126f4ea646a3c19647c3efdcf672641cff6954b Author: Konstantin Belousov AuthorDate: 2024-09-22 17:19:00 +0000 Commit: Konstantin Belousov CommitDate: 2024-09-27 15:02:29 +0000 libprocstat: add procstat_getrlimitusage() Reviewed by: markj, olce Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D46747 --- lib/libprocstat/Symbol.map | 5 ++++ lib/libprocstat/libprocstat.c | 53 +++++++++++++++++++++++++++++++++++++++++++ lib/libprocstat/libprocstat.h | 3 +++ 3 files changed, 61 insertions(+) diff --git a/lib/libprocstat/Symbol.map b/lib/libprocstat/Symbol.map index 4c8a0c7edefb..c2ea7e95312c 100644 --- a/lib/libprocstat/Symbol.map +++ b/lib/libprocstat/Symbol.map @@ -47,4 +47,9 @@ FBSD_1.6 { FBSD_1.7 { procstat_getadvlock; procstat_freeadvlock; +}; + +FBSD_1.8 { + procstat_getrlimitusage; + procstat_freerlimitusage; }; \ No newline at end of file diff --git a/lib/libprocstat/libprocstat.c b/lib/libprocstat/libprocstat.c index 0c7d28540e43..b808085f5eed 100644 --- a/lib/libprocstat/libprocstat.c +++ b/lib/libprocstat/libprocstat.c @@ -2763,3 +2763,56 @@ procstat_freeadvlock(struct procstat *procstat __unused, free(lst); } +static rlim_t * +procstat_getrlimitusage_sysctl(pid_t pid, unsigned *cntp) +{ + int error, name[4]; + rlim_t *val; + size_t len; + + name[0] = CTL_KERN; + name[1] = KERN_PROC; + name[2] = KERN_PROC_RLIMIT_USAGE; + name[3] = pid; + + len = 0; + error = sysctl(name, nitems(name), NULL, &len, NULL, 0); + if (error == -1) + return (NULL); + val = malloc(len); + if (val == NULL) + return (NULL); + + error = sysctl(name, nitems(name), val, &len, NULL, 0); + if (error == -1) { + free(val); + return (NULL); + } + *cntp = len / sizeof(rlim_t); + return (val); +} + +rlim_t * +procstat_getrlimitusage(struct procstat *procstat, struct kinfo_proc *kp, + unsigned int *cntp) +{ + switch (procstat->type) { + case PROCSTAT_KVM: + warnx("kvm method is not supported"); + return (NULL); + case PROCSTAT_SYSCTL: + return (procstat_getrlimitusage_sysctl(kp->ki_pid, cntp)); + case PROCSTAT_CORE: + warnx("core method is not supported"); + return (NULL); + default: + warnx("unknown access method: %d", procstat->type); + return (NULL); + } +} + +void +procstat_freerlimitusage(struct procstat *procstat __unused, rlim_t *resusage) +{ + free(resusage); +} diff --git a/lib/libprocstat/libprocstat.h b/lib/libprocstat/libprocstat.h index 4aba1610a05f..81a3ac05393d 100644 --- a/lib/libprocstat/libprocstat.h +++ b/lib/libprocstat/libprocstat.h @@ -211,6 +211,7 @@ void procstat_freefiles(struct procstat *procstat, struct filestat_list *head); void procstat_freeptlwpinfo(struct procstat *procstat, struct ptrace_lwpinfo *pl); +void procstat_freerlimitusage(struct procstat *procstat, rlim_t *resusage); void procstat_freevmmap(struct procstat *procstat, struct kinfo_vmentry *vmmap); struct advlock_list *procstat_getadvlock(struct procstat *procstat); @@ -250,6 +251,8 @@ int procstat_getpathname(struct procstat *procstat, struct kinfo_proc *kp, char *pathname, size_t maxlen); int procstat_getrlimit(struct procstat *procstat, struct kinfo_proc *kp, int which, struct rlimit* rlimit); +rlim_t *procstat_getrlimitusage(struct procstat *procstat, + struct kinfo_proc *kp, unsigned int *cntp); int procstat_getumask(struct procstat *procstat, struct kinfo_proc *kp, unsigned short* umask); struct kinfo_vmentry *procstat_getvmmap(struct procstat *procstat,