iPXE
reboot_cmd.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 #include <getopt.h>
00025 #include <ipxe/command.h>
00026 #include <ipxe/parseopt.h>
00027 #include <ipxe/reboot.h>
00028 
00029 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00030 
00031 /** @file
00032  *
00033  * Reboot command
00034  *
00035  */
00036 
00037 /** "reboot" options */
00038 struct reboot_options {
00039         /** Perform a warm reboot */
00040         int warm;
00041 };
00042 
00043 /** "reboot" option list */
00044 static struct option_descriptor reboot_opts[] = {
00045         OPTION_DESC ( "warm", 'w', no_argument,
00046                       struct reboot_options, warm, parse_flag ),
00047 };
00048 
00049 /** "reboot" command descriptor */
00050 static struct command_descriptor reboot_cmd =
00051         COMMAND_DESC ( struct reboot_options, reboot_opts, 0, 0, NULL );
00052 
00053 /**
00054  * The "reboot" command
00055  *
00056  * @v argc              Argument count
00057  * @v argv              Argument list
00058  * @ret rc              Return status code
00059  */
00060 static int reboot_exec ( int argc, char **argv ) {
00061         struct reboot_options opts;
00062         int rc;
00063 
00064         /* Parse options */
00065         if ( ( rc = parse_options ( argc, argv, &reboot_cmd, &opts ) ) != 0 )
00066                 return rc;
00067 
00068         /* Reboot system */
00069         reboot ( opts.warm );
00070 
00071         return 0;
00072 }
00073 
00074 /** "reboot" command */
00075 struct command reboot_command __command = {
00076         .name = "reboot",
00077         .exec = reboot_exec,
00078 };