xref: /netbsd-src/usr.bin/rump_halt/rump.halt.c (revision 23dfcd7408ac64d59d92beb90663ee97670c6648)
1 /*	$NetBSD: rump.halt.c,v 1.5 2014/11/04 19:05:17 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.5 2014/11/04 19:05:17 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 HAVE_GETPROGNAME
51 #define getprogname() "rump_halt"
52 #endif
53 
54 __dead static void
usage(void)55 usage(void)
56 {
57 
58 	fprintf(stderr, "usage: %s [-" ARGFLAGS "]\n", getprogname());
59 	exit(1);
60 }
61 
62 int
main(int argc,char * argv[])63 main(int argc, char *argv[])
64 {
65 	int ch, flags;
66 
67 	setprogname(argv[0]);
68 	flags = 0;
69 	while ((ch = getopt(argc, argv, ARGFLAGS)) != -1) {
70 		switch (ch) {
71 		case 'd':
72 			flags |= RUMP_RB_DUMP;
73 			break;
74 		case 'h':
75 			flags |= RUMP_RB_HALT;
76 			break;
77 		case 'n':
78 			flags |= RUMP_RB_NOSYNC;
79 			break;
80 		default:
81 			usage();
82 			break;
83 		}
84 	}
85 
86 	if (optind != argc)
87 		usage();
88 
89 	if (rumpclient_init() == -1)
90 		err(1, "init failed");
91 
92 	if (rump_sys_reboot(flags, NULL) == -1)
93 		err(1, "reboot");
94 
95 	return 0;
96 }
97