1 /* $NetBSD: h_forkcli.c,v 1.1 2011/01/05 17:19:09 pooka Exp $ */
14 #include <rump/rump_syscalls.h>
15 #include <rump/rumpclient.h>
20 struct rumpclient_fork
*rf
;
24 if ((pid1
= rump_sys_getpid()) < 2)
25 errx(1, "unexpected pid %d", pid1
);
27 fd
= rump_sys_open("/dev/null", O_CREAT
| O_RDWR
);
28 if (rump_sys_write(fd
, &fd
, sizeof(fd
)) != sizeof(fd
))
29 errx(1, "write newlyopened /dev/null");
31 if ((rf
= rumpclient_prefork()) == NULL
)
39 if (rumpclient_fork_init(rf
) == -1)
40 err(1, "postfork init failed");
42 if ((pid2
= rump_sys_getpid()) < 2)
43 errx(1, "unexpected pid %d", pid2
);
45 errx(1, "child and parent pids are equal");
47 /* check that we can access the fd, the close it and exit */
48 if (rump_sys_write(fd
, &fd
, sizeof(fd
)) != sizeof(fd
))
49 errx(1, "write child /dev/null");
54 * check that we can access the fd, wait for the child, and
55 * check we can still access the fd
57 if (rump_sys_write(fd
, &fd
, sizeof(fd
)) != sizeof(fd
))
58 errx(1, "write parent /dev/null");
59 if (wait(&status
) == -1)
60 err(1, "wait failed");
61 if (!WIFEXITED(status
) || WEXITSTATUS(status
) != 0)
62 errx(1, "child exited with status %d", status
);
63 if (rump_sys_write(fd
, &fd
, sizeof(fd
)) != sizeof(fd
))
64 errx(1, "write parent /dev/null");
73 /* XXX: not implemented in client / server !!! */
76 #define TESTSTR "i am your fatherrrrrrr"
77 #define TESTSLEN (sizeof(TESTSTR)-1)
81 struct rumpclient_fork
*rf
;
86 if (rump_sys_pipe(pipetti
) == -1)
89 if ((rf
= rumpclient_prefork()) == NULL
)
97 if (rumpclient_fork_init(rf
) == -1)
98 err(1, "postfork init failed");
100 memset(buf
, 0, sizeof(buf
));
101 if (rump_sys_read(pipetti
[0], buf
, TESTSLEN
) != TESTSLEN
)
103 if (strcmp(TESTSTR
, buf
) != 0)
104 errx(1, "teststring doesn't match, got %s", buf
);
107 if (rump_sys_write(pipetti
[1], TESTSTR
, TESTSLEN
) != TESTSLEN
)
108 err(1, "pipe write");
109 if (wait(&status
) == -1)
110 err(1, "wait failed");
111 if (!WIFEXITED(status
) || WEXITSTATUS(status
) != 0)
112 errx(1, "child exited with status %d", status
);
120 struct rumpclient_fork
*rf
;
124 if ((rf
= rumpclient_prefork()) == NULL
)
127 /* XXX: we know the internal structure of rf */
129 *(auth
+3) = *(auth
+3) ^ 0x1;
131 rv
= rumpclient_fork_init(rf
);
132 if (!(rv
== -1 && errno
== ESRCH
))
137 const char *arg
; /* sp arg, el */
138 void (*spring
)(void); /* spring into action */
140 { "simple", simple
},
141 { "cancel", cancel
},
142 { "pipecomm", pipecomm
},
143 { "fakeauth", fakeauth
},
147 main(int argc
, char *argv
[])
152 errx(1, "invalid usage");
154 if (rumpclient_init() == -1)
155 err(1, "rumpclient init");
157 for (i
= 0; i
< __arraycount(paragus
); i
++) {
158 if (strcmp(argv
[1], paragus
[i
].arg
) == 0) {
163 if (i
== __arraycount(paragus
)) {
164 printf("invalid test %s\n", argv
[1]);