summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/rump/rumpkern/h_server/h_simpleserver.c
blob: 4e04c2269177b7bdba38df8d7226f7dbdae02224 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*	$NetBSD: h_simpleserver.c,v 1.3 2011/01/14 13:23:15 pooka Exp $	*/

#include <sys/types.h>

#include <rump/rump.h>

#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "../../kernspace/kernspace.h"

#define NOFAIL(e) do { int rv = e; if (rv) err(1, #e); } while (/*CONSTCOND*/0)

struct {
	const char *str;
	void (*dofun)(char *);
} actions[] = {
	{ "sendsig", rumptest_sendsig },
};

int
main(int argc, char *argv[])
{
	unsigned i;
	bool match;

	if (argc < 2)
		exit(1);

	NOFAIL(rump_daemonize_begin());
	NOFAIL(rump_init());
	NOFAIL(rump_init_server(argv[1]));
	NOFAIL(rump_daemonize_done(RUMP_DAEMONIZE_SUCCESS));

	if (argc > 2) {
		char *arg = NULL;

		if (argc == 4)
			arg = argv[3];

		for (i = 0; i < __arraycount(actions); i++) {
			if (strcmp(actions[i].str, argv[2]) == 0) {
				rump_schedule();
				actions[i].dofun(arg);
				rump_unschedule();
				match = true;
			}
		}

		if (!match) {
			exit(1);
		}
		pause();
	} else {
		for (;;)
			pause();
	}

	return 0;
}
OpenPOWER on IntegriCloud