summaryrefslogtreecommitdiff
path: root/filesystems/glusterfs/patches/patch-ce
blob: e290e04fde7ce09c31e5ea47db5d2b85554d4b55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
$NetBSD: patch-ce,v 1.1 2011/12/16 05:40:46 manu Exp $

Fetch secondary groups using sysctl(2) instead of /proc, to avoid
deadlocks

--- xlators/mount/fuse/src/fuse-helpers.c.orig	2011-11-14 14:46:02.000000000 +0100
+++ xlators/mount/fuse/src/fuse-helpers.c	2011-12-15 10:49:52.000000000 +0100
@@ -17,8 +17,11 @@
    <http://www.gnu.org/licenses/>.
 */
 
 #include "fuse-bridge.h"
+#ifdef __NetBSD__
+#include <sys/sysctl.h>	/* for sysctl(2) */
+#endif /* __NetBSD__ */
 
 xlator_t *
 fuse_state_subvol (fuse_state_t *state)
 {
@@ -134,10 +137,10 @@
         return state;
 }
 
 
-void
-frame_fill_groups (call_frame_t *frame)
+static void
+frame_fill_groups_proc (call_frame_t *frame)
 {
         char         filename[128];
         char         line[128];
         char        *ptr = NULL;
@@ -184,8 +187,42 @@
                 fclose (fp);
         return;
 }
 
+#ifdef __NetBSD__
+static void
+frame_fill_groups_sysctl (call_frame_t *frame)
+{
+	int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, frame->root->pid };
+	size_t namelen = sizeof(name) / sizeof(*name);
+	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);
+
+	for (i = 0; i < ngroups; i++)
+		frame->root->groups[i] = kp.kp_eproc.e_ucred.cr_groups[i];
+	frame->root->ngrps = ngroups;
+
+
+	return;
+}
+#endif /* __NetBSD__ */
+
+void
+frame_fill_groups (call_frame_t *frame)
+{
+#if defined(linux)
+	frame_fill_groups_proc(frame);
+#elif defined(__NetBSD__)
+	frame_fill_groups_sysctl(frame);
+#endif
+	return;
+}
 
 call_frame_t *
 get_call_frame_for_req (fuse_state_t *state)
 {