rump.halt.c revision 1.4 1 /* $NetBSD: rump.halt.c,v 1.4 2014/01/15 16:53:32 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 <rump/rumpuser_port.h>
29
30 #include <sys/cdefs.h>
31 #ifndef lint
32 __RCSID("$NetBSD: rump.halt.c,v 1.4 2014/01/15 16:53:32 pooka Exp $");
33 #endif /* !lint */
34
35 #include <sys/types.h>
36
37 #include <rump/rump.h>
38 #include <rump/rumpclient.h>
39 #include <rump/rump_syscalls.h>
40
41 #include <err.h>
42 #include <errno.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #include <unistd.h>
47
48 #define ARGFLAGS "dhn"
49
50 #ifndef PLATFORM_HAS_SETGETPROGNAME
51 #define getprogname() "rump_halt"
52 #endif
53
54 __dead static void
55 usage(void)
56 {
57
58 fprintf(stderr, "usage: %s [-" ARGFLAGS "]\n", getprogname());
59 exit(1);
60 }
61
62 int
63 main(int argc, char *argv[])
64 {
65 int ch, flags;
66
67 setprogname(argv[0]);
68
69 flags = 0;
70 while ((ch = getopt(argc, argv, ARGFLAGS)) != -1) {
71 switch (ch) {
72 case 'd':
73 flags |= RUMP_RB_DUMP;
74 break;
75 case 'h':
76 flags |= RUMP_RB_HALT;
77 break;
78 case 'n':
79 flags |= RUMP_RB_NOSYNC;
80 break;
81 default:
82 usage();
83 break;
84 }
85 }
86
87 if (optind != argc)
88 usage();
89
90 if (rumpclient_init() == -1)
91 err(1, "init failed");
92
93 if (rump_sys_reboot(flags, NULL) == -1)
94 err(1, "reboot");
95
96 return 0;
97 }
98