blob: 3354f21a145008e0d667f6f60d81693c23f61123 (
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
|
$NetBSD: patch-aq,v 1.2 2000/11/27 10:59:20 rh Exp $
--- zvt/gnome-pty-helper.c.orig Sat Mar 18 08:57:13 2000
+++ zvt/gnome-pty-helper.c
@@ -115,14 +115,20 @@
#endif
#endif /* CMSG_DATA */
-#define CONTROLLEN (sizeof (struct cmsghdr) + sizeof (int))
+#ifndef CMSG_SPACE
+#include <machine/param.h>
+#define CMSG_SPACE(l) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(l))
+#define CMSG_LEN(l) (ALIGN(sizeof(struct cmsghdr)) + (l))
+#endif
-static struct cmsghdr *cmptr;
+#define FD_LEN (sizeof(int) * 1)
+
+static void *cmptr;
static int
init_msg_pass ()
{
- cmptr = malloc (CONTROLLEN);
+ cmptr = malloc (CMSG_SPACE(FD_LEN));
if (cmptr)
return 0;
@@ -135,22 +141,26 @@
{
struct iovec iov[1];
struct msghdr msg;
+ struct cmsghdr *cmp;
char buf [1];
iov [0].iov_base = buf;
iov [0].iov_len = 1;
+ memset(&msg, 0, sizeof(msg));
msg.msg_iov = iov;
msg.msg_iovlen = 1;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_control = (caddr_t) cmptr;
- msg.msg_controllen = CONTROLLEN;
+ msg.msg_controllen = CMSG_LEN(FD_LEN);
- cmptr->cmsg_level = SOL_SOCKET;
- cmptr->cmsg_type = SCM_RIGHTS;
- cmptr->cmsg_len = CONTROLLEN;
- *(int *)CMSG_DATA (cmptr) = fd;
+ memset(cmptr, 0, CMSG_SPACE(FD_LEN));
+ cmp = CMSG_FIRSTHDR(&msg);
+ cmp->cmsg_level = SOL_SOCKET;
+ cmp->cmsg_type = SCM_RIGHTS;
+ cmp->cmsg_len = CMSG_LEN(FD_LEN);
+ *(int *)CMSG_DATA (cmp) = fd;
if (sendmsg (client_fd, &msg, 0) != 1)
return -1;
|