1 /*	$NetBSD: h_simpleserver.c,v 1.3 2011/01/14 13:23:15 pooka Exp $	*/
2 
3 #include <sys/types.h>
4 
5 #include <rump/rump.h>
6 
7 #include <err.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <unistd.h>
12 
13 #include "../../kernspace/kernspace.h"
14 
15 #define NOFAIL(e) do { int rv = e; if (rv) err(1, #e); } while (/*CONSTCOND*/0)
16 
17 struct {
18 	const char *str;
19 	void (*dofun)(char *);
20 } actions[] = {
21 	{ "sendsig", rumptest_sendsig },
22 };
23 
24 int
25 main(int argc, char *argv[])
26 {
27 	unsigned i;
28 	bool match;
29 
30 	if (argc < 2)
31 		exit(1);
32 
33 	NOFAIL(rump_daemonize_begin());
34 	NOFAIL(rump_init());
35 	NOFAIL(rump_init_server(argv[1]));
36 	NOFAIL(rump_daemonize_done(RUMP_DAEMONIZE_SUCCESS));
37 
38 	if (argc > 2) {
39 		char *arg = NULL;
40 
41 		if (argc == 4)
42 			arg = argv[3];
43 
44 		for (i = 0; i < __arraycount(actions); i++) {
45 			if (strcmp(actions[i].str, argv[2]) == 0) {
46 				rump_schedule();
47 				actions[i].dofun(arg);
48 				rump_unschedule();
49 				match = true;
50 			}
51 		}
52 
53 		if (!match) {
54 			exit(1);
55 		}
56 		pause();
57 	} else {
58 		for (;;)
59 			pause();
60 	}
61 
62 	return 0;
63 }
64