You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

poweroff_cmd.c 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include <stdio.h>
  20. #include <string.h>
  21. #include <getopt.h>
  22. #include <ipxe/command.h>
  23. #include <ipxe/parseopt.h>
  24. #include <ipxe/reboot.h>
  25. FILE_LICENCE ( GPL2_OR_LATER );
  26. /** @file
  27. *
  28. * Power off command
  29. *
  30. */
  31. /** "poweroff" options */
  32. struct poweroff_options {};
  33. /** "poweroff" option list */
  34. static struct option_descriptor poweroff_opts[] = {};
  35. /** "poweroff" command descriptor */
  36. static struct command_descriptor poweroff_cmd =
  37. COMMAND_DESC ( struct poweroff_options, poweroff_opts, 0, 0, NULL );
  38. /**
  39. * The "poweroff" command
  40. *
  41. * @v argc Argument count
  42. * @v argv Argument list
  43. * @ret rc Return status code
  44. */
  45. static int poweroff_exec ( int argc, char **argv ) {
  46. struct poweroff_options opts;
  47. int rc;
  48. /* Parse options */
  49. if ( ( rc = parse_options ( argc, argv, &poweroff_cmd, &opts ) ) != 0 )
  50. return rc;
  51. /* Power off system */
  52. rc = poweroff();
  53. if ( rc != 0 )
  54. printf ( "Could not power off: %s\n", strerror ( rc ) );
  55. return rc;
  56. }
  57. /** "poweroff" command */
  58. struct command poweroff_command __command = {
  59. .name = "poweroff",
  60. .exec = poweroff_exec,
  61. };