rump_allserver.c revision 1.3 1 /* $NetBSD: rump_allserver.c,v 1.3 2010/12/12 12:49:37 pooka Exp $ */
2
3 /*-
4 * Copyright (c) 2010 Antti Kantee. All Rights Reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 #ifndef lint
30 __RCSID("$NetBSD: rump_allserver.c,v 1.3 2010/12/12 12:49:37 pooka Exp $");
31 #endif /* !lint */
32
33 #include <sys/types.h>
34
35 #include <rump/rump.h>
36
37 #include <err.h>
38 #include <errno.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <unistd.h>
43
44 static void
45 usage(void)
46 {
47
48 fprintf(stderr, "usage: %s [args] bindurl\n", getprogname());
49 exit(1);
50 }
51
52 static void
53 die(int sflag, int error, const char *reason)
54 {
55
56 warnx("%s: %s", reason, strerror(error));
57 if (!sflag)
58 rump_daemonize_done(error);
59 exit(1);
60 }
61
62 int
63 main(int argc, char *argv[])
64 {
65 const char *serverurl;
66 int error;
67 int ch, sflag;
68
69 setprogname(argv[0]);
70
71 sflag = 0;
72 while ((ch = getopt(argc, argv, "s")) != -1) {
73 switch (ch) {
74 case 's':
75 sflag = 1;
76 break;
77 default:
78 usage();
79 /*NOTREACHED*/
80 }
81 }
82
83 argc -= optind;
84 argv += optind;
85
86 if (argc != 1)
87 usage();
88
89 serverurl = argv[0];
90
91 if (!sflag) {
92 error = rump_daemonize_begin();
93 if (error)
94 errx(1, "rump daemonize: %s", strerror(error));
95 }
96
97 error = rump_init();
98 if (error)
99 die(sflag, error, "rump init failed");
100 error = rump_init_server(serverurl);
101 if (error)
102 die(sflag, error, "rump server init failed");
103
104 if (!sflag)
105 rump_daemonize_done(RUMP_DAEMONIZE_SUCCESS);
106
107 pause();
108 }
109