Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Oct 2024 07:11:28 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 1611738d4c4c - stable/14 - libprocstat: add procstat_getrlimitusage()
Message-ID:  <202410050711.4957BSfr001589@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=1611738d4c4c375ea79a5cc25dd4fa29670ad88c

commit 1611738d4c4c375ea79a5cc25dd4fa29670ad88c
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-09-22 17:19:00 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
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,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202410050711.4957BSfr001589>