Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | #include <errno.h> |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <sys/reboot.h> |
| 5 | //#include <reboot/reboot.h> |
| 6 | #include <unistd.h> |
| 7 | |
| 8 | #include "tw_reboot.h" |
| 9 | #include "recovery_ui.h" |
| 10 | #include "roots.h" |
| 11 | #include "extra-functions.h" |
| 12 | #include "data.h" |
| 13 | #include "variables.h" |
| 14 | |
| 15 | // isRebootCommandSupported: Return 1 if command is supported, 0 if the command is not supported, -1 on error |
| 16 | int tw_isRebootCommandSupported(RebootCommand command) |
| 17 | { |
| 18 | switch (command) |
| 19 | { |
| 20 | case rb_system: |
| 21 | case rb_recovery: |
| 22 | case rb_poweroff: |
| 23 | case rb_bootloader: |
| 24 | case rb_download: |
| 25 | return 1; |
| 26 | |
| 27 | default: |
| 28 | return 0; |
| 29 | } |
| 30 | return -1; |
| 31 | } |
| 32 | |
| 33 | // setRebootMode: Set the reboot state (without rebooting). Return 0 on success, -1 on error or unsupported |
| 34 | int tw_setRebootMode(RebootCommand command) |
| 35 | { |
| 36 | return -1; |
| 37 | } |
| 38 | |
| 39 | // reboot: Reboot the system. Return -1 on error, no return on success |
| 40 | int tw_reboot(RebootCommand command) |
| 41 | { |
| 42 | // Always force a sync before we reboot |
| 43 | sync(); |
| 44 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 45 | switch (command) |
| 46 | { |
| 47 | case rb_current: |
| 48 | case rb_system: |
Dees_Troy | 7d15c25 | 2012-09-05 20:47:21 -0400 | [diff] [blame] | 49 | twfinish_recovery("s"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 50 | sync(); |
| 51 | check_and_run_script("/sbin/rebootsystem.sh", "reboot system"); |
| 52 | return reboot(RB_AUTOBOOT); |
| 53 | case rb_recovery: |
| 54 | check_and_run_script("/sbin/rebootrecovery.sh", "reboot recovery"); |
| 55 | return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "recovery"); |
| 56 | case rb_bootloader: |
| 57 | check_and_run_script("/sbin/rebootbootloader.sh", "reboot bootloader"); |
| 58 | return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "bootloader"); |
| 59 | case rb_poweroff: |
| 60 | check_and_run_script("/sbin/poweroff.sh", "power off"); |
| 61 | return reboot(RB_POWER_OFF); |
| 62 | case rb_download: |
| 63 | check_and_run_script("/sbin/rebootdownload.sh", "reboot download"); |
| 64 | return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "download"); |
| 65 | return 1; |
| 66 | default: |
| 67 | return -1; |
| 68 | } |
| 69 | return -1; |
| 70 | } |
| 71 | |