From owner-freebsd-hackers@FreeBSD.ORG Tue May 14 11:13:23 2013 Return-Path: Delivered-To: freebsd-hackers@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 5E50BA6D for ; Tue, 14 May 2013 11:13:23 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id CB7C0222 for ; Tue, 14 May 2013 11:13:22 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.7/8.14.7) with ESMTP id r4EBDIvb064291; Tue, 14 May 2013 14:13:18 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua r4EBDIvb064291 Received: (from kostik@localhost) by tom.home (8.14.7/8.14.7/Submit) id r4EBDIas064290; Tue, 14 May 2013 14:13:18 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 14 May 2013 14:13:18 +0300 From: Konstantin Belousov To: Mike Ma Subject: Re: How to get ucred/xucred in user space? Message-ID: <20130514111318.GP3047@kib.kiev.ua> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="gl32Q9cg1UYx5OVO" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 May 2013 11:13:23 -0000 --gl32Q9cg1UYx5OVO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, May 14, 2013 at 10:00:21AM +0200, Mike Ma wrote: > Hi folks, >=20 > Can I ask if there's any way to get ucred/xucred of a process in user spa= ce? > As I'm trying to port glustertfs and it's a userland filesystem, I need to > get secondary groups of a process. >=20 > AFAIK, Linux gets them in /proc and NetBSD gets them in this way: > int name[] =3D { CTL_KERN, KERN_PROC, KERN_PROC_PID, frame->root-= >pid > }; > size_t namelen =3D sizeof name / sizeof name[0]; > struct kinfo_proc kp; > size_t kplen =3D sizeof(kp); > int i, ngroups; > if (sysctl(name, namelen, &kp, &kplen, NULL, 0) !=3D 0) > return; > ngroups =3D MIN(kp.kp_eproc.e_ucred.cr_ngroups, GF_REQUEST_MAXGRO= UPS); >=20 > 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. --gl32Q9cg1UYx5OVO Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iQIcBAEBAgAGBQJRkhxOAAoJEJDCuSvBvK1BizsP/2dpRVnQkTE9iydzPVc7oydc chirm8uggZ2+5hPh/Yahy04fmqSYo7UHZPAYYjCXnI8y6M2ObQJAshtJkAHDfQ5A AasUhCcR9XITIOqo4YQWIbHrMhRndYW+U4Ou8uGE68pbd9S7CWW/5GtE8e0zGRoj S8ONbgwDnsZn44sDuzzxssKLqT2qMZM/q/l4K4F8I39rZwRk0PsonvvUeBqIl5Wt IgeOaYIddNOhZ+1FKJu9L4NEAZeCgVR2DLqVnmwBQYudskalECRtu9izFtkMoQuU QwUVDFNhi3B4TiWvjSi2GDdMExkTBGJZIK0DgmPHG6PrPxHA4RGGsxkFMhxkUAVk 332JJ4Cd9CkA9bf68uHJWklwK1uD2EI9KPrQzJdSus4KOJEZb2+2wGL2QrMoxGZd HYUFpMKRiaktd0BHxa47OcLZk6kiVQLliwbnYiCa167bKlm2le5Ae/RHNaoaGsU7 0soJrkutixWh4qqpZIspK1lGpGWdnf2ROTYnkpdjQBHp9AZAABoNyUtOI7y8b3CN BbPQUjlWVeF5AqAdLW4ybVtle2YZBa16AyWceCHTBMC9Fu3sRB9gMHvUrlGygtxH wNERwJCxhyDYBGG7dIbVH1QTHO9ZtXD3d3WZbgkfOrLCdDvbnZ8ygotZjMKRLrMh SMPnPfepcJmt4J5MFYVV =qQox -----END PGP SIGNATURE----- --gl32Q9cg1UYx5OVO--