Elie De Brauwer | 9b2b24a | 2013-10-01 20:57:21 +0200 | [diff] [blame] | 1 | /* reboot.c - Restart, halt or powerdown the system. |
| 2 | * |
| 3 | * Copyright 2013 Elie De Brauwer <eliedebrauwer@gmail.com> |
| 4 | |
| 5 | USE_REBOOT(NEWTOY(reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT)) |
| 6 | USE_REBOOT(OLDTOY(halt, reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT)) |
| 7 | USE_REBOOT(OLDTOY(poweroff, reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT)) |
| 8 | |
| 9 | config REBOOT |
| 10 | bool "reboot" |
| 11 | default y |
| 12 | help |
| 13 | usage: reboot/halt/poweroff [-n] |
| 14 | |
| 15 | Restart, halt or powerdown the system. |
| 16 | |
| 17 | -n Don't sync before stopping the system. |
| 18 | */ |
| 19 | |
| 20 | #define FOR_reboot |
| 21 | #include "toys.h" |
| 22 | #include <sys/reboot.h> |
| 23 | |
| 24 | void reboot_main(void) |
| 25 | { |
Rob Landley | 4aee303 | 2013-10-17 14:43:38 -0500 | [diff] [blame] | 26 | int types[] = {RB_AUTOBOOT, RB_HALT_SYSTEM, RB_POWER_OFF}; |
Elie De Brauwer | 9b2b24a | 2013-10-01 20:57:21 +0200 | [diff] [blame] | 27 | |
Rob Landley | 4aee303 | 2013-10-17 14:43:38 -0500 | [diff] [blame] | 28 | if (!(toys.optflags & FLAG_n)) sync(); |
Elie De Brauwer | 9b2b24a | 2013-10-01 20:57:21 +0200 | [diff] [blame] | 29 | |
Rob Landley | 4aee303 | 2013-10-17 14:43:38 -0500 | [diff] [blame] | 30 | toys.exitval = reboot(types[stridx("hp", *toys.which->name)+1]); |
Elie De Brauwer | 9b2b24a | 2013-10-01 20:57:21 +0200 | [diff] [blame] | 31 | } |