blob: 9d87ff21d2d0d4a89fe55824adb67e66bd8e9f8c [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001#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
16int 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
34int tw_setRebootMode(RebootCommand command)
35{
36 return -1;
37}
38
39// reboot: Reboot the system. Return -1 on error, no return on success
40int tw_reboot(RebootCommand command)
41{
42 // Always force a sync before we reboot
43 sync();
44
Dees_Troy51a0e822012-09-05 15:24:24 -040045 switch (command)
46 {
47 case rb_current:
48 case rb_system:
Dees_Troy7d15c252012-09-05 20:47:21 -040049 twfinish_recovery("s");
Dees_Troy51a0e822012-09-05 15:24:24 -040050 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