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