mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-14 14:55:41 +00:00
libprocstat: add procstat_getrlimitusage()
Reviewed by: markj, olce Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D46747
This commit is contained in:
parent
c85d3064c4
commit
6126f4ea64
@ -47,4 +47,9 @@ FBSD_1.6 {
|
||||
FBSD_1.7 {
|
||||
procstat_getadvlock;
|
||||
procstat_freeadvlock;
|
||||
};
|
||||
|
||||
FBSD_1.8 {
|
||||
procstat_getrlimitusage;
|
||||
procstat_freerlimitusage;
|
||||
};
|
@ -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);
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user