Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / hci / commands / poweroff_cmd.c
1 /*
2  * Copyright (C) 2013 Marin Hannache <ipxe@mareo.fr>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <getopt.h>
23 #include <ipxe/command.h>
24 #include <ipxe/parseopt.h>
25 #include <ipxe/reboot.h>
26
27 FILE_LICENCE ( GPL2_OR_LATER );
28
29 /** @file
30  *
31  * Power off command
32  *
33  */
34
35 /** "poweroff" options */
36 struct poweroff_options {};
37
38 /** "poweroff" option list */
39 static struct option_descriptor poweroff_opts[] = {};
40
41 /** "poweroff" command descriptor */
42 static struct command_descriptor poweroff_cmd =
43         COMMAND_DESC ( struct poweroff_options, poweroff_opts, 0, 0, NULL );
44
45 /**
46  * The "poweroff" command
47  *
48  * @v argc              Argument count
49  * @v argv              Argument list
50  * @ret rc              Return status code
51  */
52 static int poweroff_exec ( int argc, char **argv ) {
53         struct poweroff_options opts;
54         int rc;
55
56         /* Parse options */
57         if ( ( rc = parse_options ( argc, argv, &poweroff_cmd, &opts ) ) != 0 )
58                 return rc;
59
60         /* Power off system */
61         rc = poweroff();
62         if ( rc != 0 )
63                 printf ( "Could not power off: %s\n", strerror ( rc ) );
64
65         return rc;
66 }
67
68 /** "poweroff" command */
69 struct command poweroff_command __command = {
70         .name = "poweroff",
71         .exec = poweroff_exec,
72 };