tools/llvm: Do not build with symbols
[minix3.git] / tests / lib / librumpclient / h_exec.c
blobcf2526ced63634c3b3560bc96eb5f0d64dbb4aec
1 /* $NetBSD: h_exec.c,v 1.6 2011/02/16 17:57:44 pooka Exp $ */
3 /*
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/types.h>
31 #include <sys/socket.h>
33 #include <netinet/in.h>
35 #include <err.h>
36 #include <errno.h>
37 #include <fcntl.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <unistd.h>
43 #include <rump/rumpclient.h>
44 #include <rump/rump_syscalls.h>
46 int
47 main(int argc, char *argv[])
49 struct sockaddr_in sin;
50 socklen_t slen;
51 int s1, s2;
52 char buf[12];
53 char *eargv[4];
54 char *ename;
55 extern char **environ;
57 if (rumpclient_init() == -1)
58 err(1, "init");
60 if (argc > 1) {
61 if (strcmp(argv[1], "_didexec") == 0) {
62 rumpclient_daemon(0, 0); /* detach-me-notnot */
63 s2 = atoi(argv[2]);
64 slen = sizeof(sin);
65 /* see below */
66 rump_sys_accept(s2, (struct sockaddr *)&sin, &slen);
70 /* open and listenize two TCP4 suckets */
71 if ((s1 = rump_sys_socket(PF_INET, SOCK_STREAM, 0)) == -1)
72 err(1, "socket 1");
73 if ((s2 = rump_sys_socket(PF_INET, SOCK_STREAM, 0)) == -1)
74 err(1, "socket 2");
76 memset(&sin, 0, sizeof(sin));
77 sin.sin_len = sizeof(sin);
78 sin.sin_family = AF_INET;
79 sin.sin_port = htons(1234);
81 if (rump_sys_bind(s1, (struct sockaddr *)&sin, sizeof(sin)) == -1)
82 err(1, "bind1");
83 sin.sin_port = htons(2345);
84 if (rump_sys_bind(s2, (struct sockaddr *)&sin, sizeof(sin)) == -1)
85 err(1, "bind2");
87 if (rump_sys_listen(s1, 1) == -1)
88 err(1, "listen1");
89 if (rump_sys_listen(s2, 1) == -1)
90 err(1, "listen2");
92 if (argc == 1) {
93 rumpclient_daemon(0, 0);
94 slen = sizeof(sin);
96 * "pause()", but conveniently gets rid of this helper
97 * since we were called with RUMPCLIENT_RETRYCONN_DIE set
99 rump_sys_accept(s2, (struct sockaddr *)&sin, &slen);
102 if (argc == 3 && strcmp(argv[2], "cloexec1") == 0) {
103 if (rump_sys_fcntl(s1, F_SETFD, FD_CLOEXEC) == -1) {
104 err(1, "cloexec failed");
108 sprintf(buf, "%d", s2);
110 if (argc == 3 && strcmp(argv[2], "vfork_please") == 0) {
111 switch (rumpclient_vfork()) {
112 case 0:
113 ename = __UNCONST("fourchette");
114 break;
115 case -1:
116 err(1, "vfork");
117 default:
118 ename = __UNCONST("h_ution");
119 break;
121 } else {
122 ename = __UNCONST("h_ution");
125 /* omstart! */
126 eargv[0] = ename;
127 eargv[1] = __UNCONST("_didexec");
128 eargv[2] = buf;
129 eargv[3] = NULL;
130 if (rumpclient_exec(argv[1], __UNCONST(eargv), environ) == -1)
131 err(1, "exec");