How to get ucred/xucred in user space?
Konstantin Belousov
kostikbel at gmail.com
Tue May 14 11:13:23 UTC 2013
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20130514/4a32d68f/attachment.sig>
More information about the freebsd-hackers
mailing list