forked from Tasssadar/multirom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
86 lines (69 loc) · 1.81 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdlib.h>
#include <unistd.h>
#include <cutils/android_reboot.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/mount.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include "multirom.h"
#include "framebuffer.h"
#include "log.h"
#include "version.h"
#include "util.h"
#define EXEC_MASK (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
#define KEEP_REALDATA "/dev/.keep_realdata"
#define REALDATA "/realdata"
static void do_reboot(int exit)
{
sync();
umount(REALDATA);
if(exit & EXIT_REBOOT_RECOVERY) android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
else if(exit & EXIT_REBOOT_BOOTLOADER) android_reboot(ANDROID_RB_RESTART2, 0, "bootloader");
else if(exit & EXIT_SHUTDOWN) android_reboot(ANDROID_RB_POWEROFF, 0, 0);
else android_reboot(ANDROID_RB_RESTART, 0, 0);
while(1);
}
static void do_kexec(void)
{
sync();
umount(REALDATA);
execl("/kexec", "/kexec", "-e", NULL);
ERROR("kexec -e failed! (%d: %s)", errno, strerror(errno));
while(1);
}
int main(int argc, char *argv[])
{
int i;
for(i = 1; i < argc; ++i)
{
if(strcmp(argv[i], "-v") == 0)
{
printf("%d\n", VERSION_MULTIROM);
return 0;
}
}
srand(time(0));
klog_init();
ERROR("Running MultiROM v%d\n", VERSION_MULTIROM);
int exit = multirom();
if(exit >= 0)
{
if(exit & EXIT_REBOOT_MASK)
{
do_reboot(exit);
return 0;
}
if(exit & EXIT_KEXEC)
{
do_kexec();
return 0;
}
// indicates trampoline to keep /realdata mounted
if(!(exit & EXIT_UMOUNT))
close(open(KEEP_REALDATA, O_WRONLY | O_CREAT, 0000));
}
vt_set_mode(0);
return 0;
}