| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: t_cmsg.c,v 1.8 2009/10/14 18:22:50 pooka Exp $ */ | | 1 | /* $NetBSD: t_cmsg.c,v 1.9 2009/10/15 16:47:23 pooka Exp $ */ |
2 | | | 2 | |
3 | #include <sys/types.h> | | 3 | #include <sys/types.h> |
4 | #include <sys/mount.h> | | 4 | #include <sys/mount.h> |
5 | #include <sys/socket.h> | | 5 | #include <sys/socket.h> |
6 | #include <sys/un.h> | | 6 | #include <sys/un.h> |
7 | | | 7 | |
8 | #include <rump/rump.h> | | 8 | #include <rump/rump.h> |
9 | #include <rump/rump_syscalls.h> | | 9 | #include <rump/rump_syscalls.h> |
10 | | | 10 | |
11 | #include <fs/tmpfs/tmpfs_args.h> | | 11 | #include <fs/tmpfs/tmpfs_args.h> |
12 | | | 12 | |
13 | #include <atf-c.h> | | 13 | #include <atf-c.h> |
14 | #include <fcntl.h> | | 14 | #include <fcntl.h> |
| @@ -94,42 +94,42 @@ ATF_TC_BODY(cmsg_sendfd, tc) | | | @@ -94,42 +94,42 @@ ATF_TC_BODY(cmsg_sendfd, tc) |
94 | | | 94 | |
95 | memset(&args, 0, sizeof(args)); | | 95 | memset(&args, 0, sizeof(args)); |
96 | args.ta_version = TMPFS_ARGS_VERSION; | | 96 | args.ta_version = TMPFS_ARGS_VERSION; |
97 | args.ta_root_mode = 0777; | | 97 | args.ta_root_mode = 0777; |
98 | | | 98 | |
99 | rump_init(); | | 99 | rump_init(); |
100 | /* | | 100 | /* |
101 | * mount tmpfs as root -- rump root file system does not support | | 101 | * mount tmpfs as root -- rump root file system does not support |
102 | * unix domain sockets. | | 102 | * unix domain sockets. |
103 | */ | | 103 | */ |
104 | if (rump_sys_mount(MOUNT_TMPFS, "/", 0, &args, sizeof(args)) == -1) | | 104 | if (rump_sys_mount(MOUNT_TMPFS, "/", 0, &args, sizeof(args)) == -1) |
105 | atf_tc_fail_errno("mount tmpfs"); | | 105 | atf_tc_fail_errno("mount tmpfs"); |
106 | | | 106 | |
| | | 107 | /* store our current lwp/proc */ |
| | | 108 | l1 = rump_pub_newproc_switch(); |
| | | 109 | |
107 | /* create unix socket and bind it to a path */ | | 110 | /* create unix socket and bind it to a path */ |
108 | memset(&sun, 0, sizeof(sun)); | | 111 | memset(&sun, 0, sizeof(sun)); |
109 | sun.sun_family = AF_LOCAL; | | 112 | sun.sun_family = AF_LOCAL; |
110 | #define SOCKPATH "/com" | | 113 | #define SOCKPATH "/com" |
111 | strncpy(sun.sun_path, SOCKPATH, sizeof(SOCKPATH)); | | 114 | strncpy(sun.sun_path, SOCKPATH, sizeof(SOCKPATH)); |
112 | s1 = rump_sys_socket(AF_LOCAL, SOCK_STREAM, 0); | | 115 | s1 = rump_sys_socket(AF_LOCAL, SOCK_STREAM, 0); |
113 | if (s1 == -1) | | 116 | if (s1 == -1) |
114 | atf_tc_fail_errno("socket 1"); | | 117 | atf_tc_fail_errno("socket 1"); |
115 | if (rump_sys_bind(s1, (struct sockaddr *)&sun, SUN_LEN(&sun)) == -1) | | 118 | if (rump_sys_bind(s1, (struct sockaddr *)&sun, SUN_LEN(&sun)) == -1) |
116 | atf_tc_fail_errno("socket 1 bind"); | | 119 | atf_tc_fail_errno("socket 1 bind"); |
117 | if (rump_sys_listen(s1, 1) == -1) | | 120 | if (rump_sys_listen(s1, 1) == -1) |
118 | atf_tc_fail_errno("socket 1 listen"); | | 121 | atf_tc_fail_errno("socket 1 listen"); |
119 | | | 122 | |
120 | /* store our current lwp/proc */ | | | |
121 | l1 = rump_pub_get_curlwp(); | | | |
122 | | | | |
123 | /* create new process */ | | 123 | /* create new process */ |
124 | l2 = rump_pub_newproc_switch(); | | 124 | l2 = rump_pub_newproc_switch(); |
125 | | | 125 | |
126 | /* connect to unix domain socket */ | | 126 | /* connect to unix domain socket */ |
127 | memset(&sun, 0, sizeof(sun)); | | 127 | memset(&sun, 0, sizeof(sun)); |
128 | sun.sun_family = AF_LOCAL; | | 128 | sun.sun_family = AF_LOCAL; |
129 | strncpy(sun.sun_path, SOCKPATH, sizeof(SOCKPATH)); | | 129 | strncpy(sun.sun_path, SOCKPATH, sizeof(SOCKPATH)); |
130 | s2 = rump_sys_socket(AF_LOCAL, SOCK_STREAM, 0); | | 130 | s2 = rump_sys_socket(AF_LOCAL, SOCK_STREAM, 0); |
131 | if (s2 == -1) | | 131 | if (s2 == -1) |
132 | atf_tc_fail_errno("socket 2"); | | 132 | atf_tc_fail_errno("socket 2"); |
133 | if (rump_sys_connect(s2, (struct sockaddr *)&sun, SUN_LEN(&sun)) == -1) | | 133 | if (rump_sys_connect(s2, (struct sockaddr *)&sun, SUN_LEN(&sun)) == -1) |
134 | atf_tc_fail_errno("socket 2 connect"); | | 134 | atf_tc_fail_errno("socket 2 connect"); |
135 | | | 135 | |
| @@ -156,27 +156,27 @@ ATF_TC_BODY(cmsg_sendfd, tc) | | | @@ -156,27 +156,27 @@ ATF_TC_BODY(cmsg_sendfd, tc) |
156 | msg.msg_iov = &iov; | | 156 | msg.msg_iov = &iov; |
157 | msg.msg_iovlen = 1; | | 157 | msg.msg_iovlen = 1; |
158 | msg.msg_name = NULL; | | 158 | msg.msg_name = NULL; |
159 | msg.msg_namelen = 0; | | 159 | msg.msg_namelen = 0; |
160 | msg.msg_control = cmp; | | 160 | msg.msg_control = cmp; |
161 | msg.msg_controllen = CMSG_LEN(sizeof(int)); | | 161 | msg.msg_controllen = CMSG_LEN(sizeof(int)); |
162 | *(int *)CMSG_DATA(cmp) = fd; | | 162 | *(int *)CMSG_DATA(cmp) = fd; |
163 | | | 163 | |
164 | /* pass the fd */ | | 164 | /* pass the fd */ |
165 | if (rump_sys_sendmsg(s2, &msg, 0) == -1) | | 165 | if (rump_sys_sendmsg(s2, &msg, 0) == -1) |
166 | atf_tc_fail_errno("sendmsg failed"); | | 166 | atf_tc_fail_errno("sendmsg failed"); |
167 | | | 167 | |
168 | /* switch back to original proc */ | | 168 | /* switch back to original proc */ |
169 | rump_set_curlwp(l1); | | 169 | rump_pub_lwp_switch(l1); |
170 | | | 170 | |
171 | /* accept connection and read fd */ | | 171 | /* accept connection and read fd */ |
172 | sl = sizeof(sun); | | 172 | sl = sizeof(sun); |
173 | sgot = rump_sys_accept(s1, (struct sockaddr *)&sun, &sl); | | 173 | sgot = rump_sys_accept(s1, (struct sockaddr *)&sun, &sl); |
174 | if (sgot == -1) | | 174 | if (sgot == -1) |
175 | atf_tc_fail_errno("accept"); | | 175 | atf_tc_fail_errno("accept"); |
176 | if (rump_sys_recvmsg(sgot, &msg, 0) == -1) | | 176 | if (rump_sys_recvmsg(sgot, &msg, 0) == -1) |
177 | atf_tc_fail_errno("recvmsg failed"); | | 177 | atf_tc_fail_errno("recvmsg failed"); |
178 | rfd = *(int *)CMSG_DATA(cmp); | | 178 | rfd = *(int *)CMSG_DATA(cmp); |
179 | | | 179 | |
180 | /* read from the fd */ | | 180 | /* read from the fd */ |
181 | memset(buf, 0, sizeof(buf)); | | 181 | memset(buf, 0, sizeof(buf)); |
182 | if (rump_sys_read(rfd, buf, sizeof(buf)) == -1) | | 182 | if (rump_sys_read(rfd, buf, sizeof(buf)) == -1) |