From owner-svn-src-head@FreeBSD.ORG Sat Apr 20 07:55:32 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id B27FA9C; Sat, 20 Apr 2013 07:55:32 +0000 (UTC) (envelope-from trociny@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id A4EFE11CF; Sat, 20 Apr 2013 07:55:32 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r3K7tW9T094964; Sat, 20 Apr 2013 07:55:32 GMT (envelope-from trociny@svn.freebsd.org) Received: (from trociny@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r3K7tW6J094952; Sat, 20 Apr 2013 07:55:32 GMT (envelope-from trociny@svn.freebsd.org) Message-Id: <201304200755.r3K7tW6J094952@svn.freebsd.org> From: Mikolaj Golub Date: Sat, 20 Apr 2013 07:55:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r249671 - head/usr.bin/procstat X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Apr 2013 07:55:32 -0000 Author: trociny Date: Sat Apr 20 07:55:31 2013 New Revision: 249671 URL: http://svnweb.freebsd.org/changeset/base/249671 Log: Use procstat_getgroups(3) for retrieving groups information instead of direct sysctl. MFC after: 1 month Modified: head/usr.bin/procstat/procstat.c head/usr.bin/procstat/procstat.h head/usr.bin/procstat/procstat_cred.c Modified: head/usr.bin/procstat/procstat.c ============================================================================== --- head/usr.bin/procstat/procstat.c Sat Apr 20 07:54:07 2013 (r249670) +++ head/usr.bin/procstat/procstat.c Sat Apr 20 07:55:31 2013 (r249671) @@ -75,7 +75,7 @@ procstat(struct procstat *prstat, struct 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) Modified: head/usr.bin/procstat/procstat.h ============================================================================== --- head/usr.bin/procstat/procstat.h Sat Apr 20 07:54:07 2013 (r249670) +++ head/usr.bin/procstat/procstat.h Sat Apr 20 07:55:31 2013 (r249671) @@ -38,7 +38,7 @@ void procstat_args(struct kinfo_proc *ki 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); Modified: head/usr.bin/procstat/procstat_cred.c ============================================================================== --- head/usr.bin/procstat/procstat_cred.c Sat Apr 20 07:54:07 2013 (r249670) +++ head/usr.bin/procstat/procstat_cred.c Sat Apr 20 07:55:31 2013 (r249671) @@ -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"); }