Use procstat_getgroups(3) for retrieving groups information instead of
direct sysctl. MFC after: 1 month
This commit is contained in:
parent
7f1d14e6e6
commit
e40d6078cd
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=249671
@ -75,7 +75,7 @@ procstat(struct procstat *prstat, struct kinfo_proc *kipp)
|
||||
else if (lflag)
|
||||
procstat_rlimit(kipp);
|
||||
else if (sflag)
|
||||
procstat_cred(kipp);
|
||||
procstat_cred(prstat, kipp);
|
||||
else if (tflag)
|
||||
procstat_threads(prstat, kipp);
|
||||
else if (vflag)
|
||||
|
@ -38,7 +38,7 @@ void procstat_args(struct kinfo_proc *kipp);
|
||||
void procstat_auxv(struct kinfo_proc *kipp);
|
||||
void procstat_basic(struct kinfo_proc *kipp);
|
||||
void procstat_bin(struct kinfo_proc *kipp);
|
||||
void procstat_cred(struct kinfo_proc *kipp);
|
||||
void procstat_cred(struct procstat *prstat, struct kinfo_proc *kipp);
|
||||
void procstat_env(struct kinfo_proc *kipp);
|
||||
void procstat_files(struct procstat *prstat, struct kinfo_proc *kipp);
|
||||
void procstat_kstack(struct kinfo_proc *kipp, int kflag);
|
||||
|
@ -41,13 +41,10 @@
|
||||
static const char *get_umask(struct kinfo_proc *kipp);
|
||||
|
||||
void
|
||||
procstat_cred(struct kinfo_proc *kipp)
|
||||
procstat_cred(struct procstat *procstat, struct kinfo_proc *kipp)
|
||||
{
|
||||
int i;
|
||||
int mib[4];
|
||||
int ngroups;
|
||||
size_t len;
|
||||
gid_t *groups = NULL;
|
||||
unsigned int i, ngroups;
|
||||
gid_t *groups;
|
||||
|
||||
if (!hflag)
|
||||
printf("%5s %-16s %5s %5s %5s %5s %5s %5s %5s %5s %-15s\n",
|
||||
@ -66,30 +63,14 @@ procstat_cred(struct kinfo_proc *kipp)
|
||||
printf("%s", kipp->ki_cr_flags & CRED_FLAG_CAPMODE ? "C" : "-");
|
||||
printf(" ");
|
||||
|
||||
groups = NULL;
|
||||
/*
|
||||
* We may have too many groups to fit in kinfo_proc's statically
|
||||
* sized storage. If that occurs, attempt to retrieve them via
|
||||
* sysctl.
|
||||
* sized storage. If that occurs, attempt to retrieve them using
|
||||
* libprocstat.
|
||||
*/
|
||||
if (kipp->ki_cr_flags & KI_CRF_GRP_OVERFLOW) {
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC;
|
||||
mib[2] = KERN_PROC_GROUPS;
|
||||
mib[3] = kipp->ki_pid;
|
||||
|
||||
ngroups = sysconf(_SC_NGROUPS_MAX) + 1;
|
||||
len = ngroups * sizeof(gid_t);
|
||||
if((groups = malloc(len)) == NULL)
|
||||
err(-1, "malloc");
|
||||
|
||||
if (sysctl(mib, 4, groups, &len, NULL, 0) == -1) {
|
||||
warn("sysctl: kern.proc.groups: %d "
|
||||
"group list truncated", kipp->ki_pid);
|
||||
free(groups);
|
||||
groups = NULL;
|
||||
}
|
||||
ngroups = len / sizeof(gid_t);
|
||||
}
|
||||
if (kipp->ki_cr_flags & KI_CRF_GRP_OVERFLOW)
|
||||
groups = procstat_getgroups(procstat, kipp, &ngroups);
|
||||
if (groups == NULL) {
|
||||
ngroups = kipp->ki_ngroups;
|
||||
groups = kipp->ki_groups;
|
||||
@ -97,7 +78,7 @@ procstat_cred(struct kinfo_proc *kipp)
|
||||
for (i = 0; i < ngroups; i++)
|
||||
printf("%s%d", (i > 0) ? "," : "", groups[i]);
|
||||
if (groups != kipp->ki_groups)
|
||||
free(groups);
|
||||
procstat_freegroups(procstat, groups);
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user