Fix unreleased resource in rootfs

This commit is contained in:
topjohnwu 2017-12-16 04:40:54 +08:00
parent 8ca1e43533
commit 17f0fea3fc
4 changed files with 21 additions and 9 deletions

View File

@ -410,8 +410,6 @@ static int prepare_img() {
if (magiskloop == NULL) if (magiskloop == NULL)
return 1; return 1;
vec_init(&module_list);
xmkdir(COREDIR, 0755); xmkdir(COREDIR, 0755);
xmkdir(COREDIR "/post-fs-data.d", 0755); xmkdir(COREDIR "/post-fs-data.d", 0755);
xmkdir(COREDIR "/service.d", 0755); xmkdir(COREDIR "/service.d", 0755);
@ -506,6 +504,7 @@ void post_fs_data(int client) {
// Allocate buffer // Allocate buffer
if (buf == NULL) buf = xmalloc(PATH_MAX); if (buf == NULL) buf = xmalloc(PATH_MAX);
if (buf2 == NULL) buf2 = xmalloc(PATH_MAX); if (buf2 == NULL) buf2 = xmalloc(PATH_MAX);
vec_init(&module_list);
// Initialize // Initialize
if (!is_daemon_init) if (!is_daemon_init)
@ -627,6 +626,7 @@ void late_start(int client) {
// Wait till the full patch is done // Wait till the full patch is done
wait_till_exists(PATCHDONE); wait_till_exists(PATCHDONE);
unlink(PATCHDONE);
// Run scripts after full patch, most reliable way to run scripts // Run scripts after full patch, most reliable way to run scripts
LOGI("* Running service.d scripts\n"); LOGI("* Running service.d scripts\n");

View File

@ -127,6 +127,7 @@ void daemon_init() {
rm_rf("/data/magisk"); rm_rf("/data/magisk");
unlink("/data/magisk.img"); unlink("/data/magisk.img");
unlink("/data/magisk_debug.log"); unlink("/data/magisk_debug.log");
chmod("/data/adb", 0700);
// Use shell glob to match files // Use shell glob to match files
exec_command_sync("sh", "-c", exec_command_sync("sh", "-c",
@ -154,13 +155,6 @@ void daemon_init() {
} }
close(sbin); close(sbin);
// Backward compatibility
xsymlink(DATABIN, "/data/magisk");
xsymlink(MAINIMG, "/data/magisk.img");
xsymlink(MOUNTPOINT, "/magisk");
xmount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL);
xmount("tmpfs", "/sbin", "tmpfs", 0, NULL); xmount("tmpfs", "/sbin", "tmpfs", 0, NULL);
chmod("/sbin", 0755); chmod("/sbin", 0755);
setfilecon("/sbin", "u:object_r:rootfs:s0"); setfilecon("/sbin", "u:object_r:rootfs:s0");
@ -181,6 +175,13 @@ void daemon_init() {
} }
close(root); close(root);
// Backward compatibility
xsymlink(DATABIN, "/data/magisk");
xsymlink(MAINIMG, "/data/magisk.img");
xsymlink(MOUNTPOINT, "/magisk");
xmount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL);
LOGI("* Mounting mirrors"); LOGI("* Mounting mirrors");
struct vector mounts; struct vector mounts;
vec_init(&mounts); vec_init(&mounts);

View File

@ -362,6 +362,12 @@ static void magisk_init_daemon() {
// Wait till init cold boot done // Wait till init cold boot done
wait_till_exists("/dev/.coldboot_done"); wait_till_exists("/dev/.coldboot_done");
int null = open("/dev/null", O_RDWR | O_CLOEXEC);
dup3(null, STDIN_FILENO, O_CLOEXEC);
dup3(null, STDOUT_FILENO, O_CLOEXEC);
dup3(null, STDERR_FILENO, O_CLOEXEC);
close(null);
// Transit our context to su (mimic setcon) // Transit our context to su (mimic setcon)
int fd, crap; int fd, crap;
fd = open("/proc/self/attr/current", O_WRONLY); fd = open("/proc/self/attr/current", O_WRONLY);
@ -414,6 +420,8 @@ int main(int argc, char *argv[]) {
dup3(null, STDIN_FILENO, O_CLOEXEC); dup3(null, STDIN_FILENO, O_CLOEXEC);
dup3(null, STDOUT_FILENO, O_CLOEXEC); dup3(null, STDOUT_FILENO, O_CLOEXEC);
dup3(null, STDERR_FILENO, O_CLOEXEC); dup3(null, STDERR_FILENO, O_CLOEXEC);
if (null > STDERR_FILENO)
close(null);
// Extract and link files // Extract and link files
mkdir("/overlay", 0000); mkdir("/overlay", 0000);
@ -504,6 +512,8 @@ int main(int argc, char *argv[]) {
if (fork_dont_care() == 0) { if (fork_dont_care() == 0) {
strcpy(argv[0], "magiskinit"); strcpy(argv[0], "magiskinit");
close(overlay);
close(root);
magisk_init_daemon(); magisk_init_daemon();
} }
} }

View File

@ -76,6 +76,7 @@ static void lazy_unmount(const char* mountpoint) {
static void hide_daemon(int pid, int ppid) { static void hide_daemon(int pid, int ppid) {
LOGD("hide_daemon: start unmount for pid=[%d]\n", pid); LOGD("hide_daemon: start unmount for pid=[%d]\n", pid);
strcpy(argv0, "hide_daemon");
char *line, buffer[PATH_MAX]; char *line, buffer[PATH_MAX];
struct vector mount_list; struct vector mount_list;