On Tue, May 14, 2013 at 10:00:21AM +0200, Mike Ma wrote:
> Hi folks,
> 
> Can I ask if there's any way to get ucred/xucred of a process in user space?
> As I'm trying to port glustertfs and it's a userland filesystem, I need to
> get secondary groups of a process.
> 
> AFAIK, Linux gets them in /proc and NetBSD gets them in this way:
>         int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, frame->root->pid
> };
>         size_t namelen = sizeof name / sizeof name[0];
>         struct kinfo_proc kp;
>         size_t kplen = sizeof(kp);
> int i, ngroups;
>         if (sysctl(name, namelen, &kp, &kplen, NULL, 0) != 0)
>                 return;
>         ngroups = MIN(kp.kp_eproc.e_ucred.cr_ngroups, GF_REQUEST_MAXGROUPS);
> 
> I realized none of them would work in FreeBSD.
> I'm wondering if there's any alternative way to get group information?

The sysctl to retrieve the list of the groups the process belongs to
is CTL_KERN/KERN_PROC/KERN_PROC_GROUPS. On HEAD, the libprocstat(3)
contains the helper procstat_getgroups() which would be more
conventient to use, or you could borrow a code from it.

Attachment: pgpmzj11Nd2Ld.pgp
Description: PGP signature

Reply via email to