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 | { |
| 26 | char c = toys.which->name[0]; |
| 27 | |
| 28 | if (!(toys.optflags & FLAG_n)) |
| 29 | sync(); |
| 30 | |
| 31 | switch(c) { |
| 32 | case 'p': |
| 33 | toys.exitval = reboot(RB_POWER_OFF); |
| 34 | break; |
| 35 | case 'h': |
| 36 | toys.exitval = reboot(RB_HALT_SYSTEM); |
| 37 | break; |
| 38 | case 'r': |
| 39 | default: |
| 40 | toys.exitval = reboot(RB_AUTOBOOT); |
| 41 | } |
| 42 | } |