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