iPXE
poweroff_cmd.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2013 Marin Hannache <ipxe@mareo.fr>.
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 <stdio.h>
00025 #include <string.h>
00026 #include <getopt.h>
00027 #include <ipxe/command.h>
00028 #include <ipxe/parseopt.h>
00029 #include <ipxe/reboot.h>
00030 
00031 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00032 
00033 /** @file
00034  *
00035  * Power off command
00036  *
00037  */
00038 
00039 /** "poweroff" options */
00040 struct poweroff_options {};
00041 
00042 /** "poweroff" option list */
00043 static struct option_descriptor poweroff_opts[] = {};
00044 
00045 /** "poweroff" command descriptor */
00046 static struct command_descriptor poweroff_cmd =
00047         COMMAND_DESC ( struct poweroff_options, poweroff_opts, 0, 0, NULL );
00048 
00049 /**
00050  * The "poweroff" command
00051  *
00052  * @v argc              Argument count
00053  * @v argv              Argument list
00054  * @ret rc              Return status code
00055  */
00056 static int poweroff_exec ( int argc, char **argv ) {
00057         struct poweroff_options opts;
00058         int rc;
00059 
00060         /* Parse options */
00061         if ( ( rc = parse_options ( argc, argv, &poweroff_cmd, &opts ) ) != 0 )
00062                 return rc;
00063 
00064         /* Power off system */
00065         rc = poweroff();
00066         if ( rc != 0 )
00067                 printf ( "Could not power off: %s\n", strerror ( rc ) );
00068 
00069         return rc;
00070 }
00071 
00072 /** "poweroff" command */
00073 struct command poweroff_command __command = {
00074         .name = "poweroff",
00075         .exec = poweroff_exec,
00076 };