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