summaryrefslogtreecommitdiff
path: root/x11/gnome-libs/patches/patch-ap
blob: 58604dafdaa2507c4fb2e3bfc326264773fc56d4 (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
$NetBSD: patch-ap,v 1.1 2000/11/11 02:07:57 mycroft Exp $

--- zvt/subshell.c.orig	Sat Nov 11 01:59:48 2000
+++ zvt/subshell.c	Sat Nov 11 01:59:11 2000
@@ -101,32 +101,43 @@
 #endif
 #endif /* CMSG_DATA */
 
-static struct cmsghdr *cmptr;
-#define CONTROLLEN  sizeof (struct cmsghdr) + sizeof (int)
+#define	FD_LEN	(sizeof(int) * 1)
+
+static void *cmptr;
 
 static int
 receive_fd (int helper_fd)
 {
 	struct iovec iov [1];
 	struct msghdr msg;
+	struct cmsghdr *cmp;
 	char buf [32];
 	
+	if (cmptr == NULL && (cmptr = g_malloc (CMSG_SPACE(FD_LEN))) == NULL)
+		return -1;
+
 	iov [0].iov_base = buf;
 	iov [0].iov_len  = sizeof (buf);
+
+	memset(&msg, 0, sizeof(msg));
 	msg.msg_iov      = iov;
 	msg.msg_iovlen   = 1;
 	msg.msg_name     = NULL;
 	msg.msg_namelen  = 0;
-
-	if (cmptr == NULL && (cmptr = g_malloc (CONTROLLEN)) == NULL)
-		return -1;
 	msg.msg_control = (caddr_t) cmptr;
-	msg.msg_controllen = CONTROLLEN;
+	msg.msg_controllen = CMSG_LEN(FD_LEN);
 
+	memset(cmptr, 0, CMSG_SPACE(FD_LEN));
 	if (recvmsg (helper_fd, &msg, 0) <= 0)
 		return -1;
 
-	return *(int *) CMSG_DATA (cmptr);
+	for (cmp = CMSG_FIRSTHDR(&msg); cmp != NULL;
+	     cmp = CMSG_NXTHDR(&msg, cmp)) {
+		if (cmp->cmsg_type == SCM_RIGHTS)
+			return *(int *) CMSG_DATA (cmp);
+	}
+
+	return -1;
 }
 
 static int