From nobody Sat Oct 05 07:11:28 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 4XLGmd1f8Lz5XrpK; Sat, 05 Oct 2024 07:11:29 +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 4XLGmc5ZkRz4NYR; Sat, 5 Oct 2024 07:11:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728112288; 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=lg8e5jfV/JmsrSgp5JUTDRib2RNNazs0ak7qMolin4E=; b=LCmcAniaNTU6c0Nsvm0ihd6TvtWQh9yFmtCrfYbz9gsEE5astvgPDthV+jxOR607EWkFMK BYwQIGiUPleBD4mcOhexyxGaWdnsxoUuyM+05ofMWofmRdEC+6okeD+LhHDwLn5a+R9EX6 e0RkZs/52w5YQZIZZiRaVNj/OHFe8YR9QoIGDPS4JN1++ySCfCqFcGKX+0AoEtln9EtE2r qpelm9iQ937rq7ynsVtBp4YBxu59jmte3gGPS+PWu3MiIaYlrxZ2nmuhJRU8ri0LJ2r8Be dMdOjd7ljybMGndVdP/8iQlKHWhWivYficQ5hzk/6LSqtXDBjjtPWEoB7eFWww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728112288; 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=lg8e5jfV/JmsrSgp5JUTDRib2RNNazs0ak7qMolin4E=; b=ih2hVohF6nSmsmTmrFJPecr4AAZmYD/HqKzbuPx51MUWnhq4vp/RrGXYoT8EgxTuNr2AN2 kQz8G2hie+iEPBRe61jRXU9Dlgc1SHOVli9vRn5ScONvNCdkNwKu1dUV4ZdukciBdvGSFB GbaU07dZnKnPpEnXKsZsH5TTJXrAxeXQ4eHOgd7zZwvkXiLsrawOhjVmIV1eBdvtUN0mTA wmu/zay32YrHEfKoaPIgxqpbudn04sHIuT5U/HcX91iUtRstb03yEmX/KD2SqqNyhG7Ntf rotjA8VfPuyHhXlRCHf0SLURZWtKhc20GKN7xft7tDdb02Z5N46WMg64UiWIVg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728112288; a=rsa-sha256; cv=none; b=cT9Mxewoyf6xFIgSmnz+fzhJLzxwGD22ZHAWEQfKpPacqQVlaWfEZoHeJLR0aAfmwOGlKn 6vWjoaPt7BjSmfYBA6CU0aY+ccR6c4azEd5Fjg02FpTM2CXvh6PahXRD0IThsIctHM85oH p/VJ5GJPt3Mtzso6m0ywg/hM0l1BUtOMrM7NIVM8bNddMdBX363LfH57PDNXXChZKcf9z8 t2PF23K/cu8WV8EkJ2KIPDjKPJAJI+ypfp9q4GHlBD8yyBUHQmbtPiK1GY9Sb9uoMdbz4g eBf2I/IrEeBmCNROkHXLo/vStS2cNQn9o6EVW5+pA8/mW6Q+tEqVbn3F5W8fLg== 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 4XLGmc54lLz17jB; Sat, 5 Oct 2024 07:11:28 +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 4957BSjr001592; Sat, 5 Oct 2024 07:11:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4957BSfr001589; Sat, 5 Oct 2024 07:11:28 GMT (envelope-from git) Date: Sat, 5 Oct 2024 07:11:28 GMT Message-Id: <202410050711.4957BSfr001589@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: 1611738d4c4c - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 1611738d4c4c375ea79a5cc25dd4fa29670ad88c Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=1611738d4c4c375ea79a5cc25dd4fa29670ad88c commit 1611738d4c4c375ea79a5cc25dd4fa29670ad88c Author: Konstantin Belousov AuthorDate: 2024-09-22 17:19:00 +0000 Commit: Konstantin Belousov CommitDate: 2024-10-05 07:08:56 +0000 libprocstat: add procstat_getrlimitusage() (cherry picked from commit 6126f4ea646a3c19647c3efdcf672641cff6954b) --- 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 c6a225a021a7..fd9578e9f115 100644 --- a/lib/libprocstat/libprocstat.c +++ b/lib/libprocstat/libprocstat.c @@ -2785,3 +2785,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 3d30b4db4018..99c005ff24a7 100644 --- a/lib/libprocstat/libprocstat.h +++ b/lib/libprocstat/libprocstat.h @@ -212,6 +212,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); @@ -251,6 +252,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,