Update restorecon implementation

This commit is contained in:
topjohnwu
2018-06-03 14:43:03 +08:00
parent ef2f8d485b
commit 34dcf49fbc
6 changed files with 79 additions and 35 deletions

View File

@ -311,11 +311,11 @@ static void clone_skeleton(struct node_entry *node) {
if (IS_LNK(child)) {
// Copy symlinks directly
cp_afc(buf2, buf);
#ifdef MAGISK_DEBUG
LOGI("creat_link: %s <- %s\n",buf, buf2);
#else
LOGI("creat_link: %s\n", buf);
#endif
#ifdef MAGISK_DEBUG
LOGI("creat_link: %s <- %s\n",buf, buf2);
#else
LOGI("creat_link: %s\n", buf);
#endif
} else {
snprintf(buf, PATH_MAX, "%s/%s", full_path, child->name);
bind_mount(buf2, buf);
@ -449,18 +449,9 @@ static int prepare_img() {
// Remount them back :)
magiskloop = mount_image(MAINIMG, MOUNTPOINT);
free(magiskloop);
// Fix file selinux contexts
fix_filecon();
return 0;
}
void fix_filecon() {
int dirfd = xopen(MOUNTPOINT, O_RDONLY | O_CLOEXEC);
restorecon(dirfd);
close(dirfd);
}
/****************
* Entry points *
****************/
@ -675,6 +666,8 @@ void post_fs_data(int client) {
if (prepare_img())
goto core_only; // Mounting fails, we can only do core only stuffs
restorecon();
// Run common scripts
LOGI("* Running post-fs-data.d scripts\n");
exec_common_script("post-fs-data");

View File

@ -136,7 +136,7 @@ int magisk_main(int argc, char *argv[]) {
unlock_blocks();
return 0;
} else if (strcmp(argv[1], "--restorecon") == 0) {
fix_filecon();
restorecon();
return 0;
} else if (strcmp(argv[1], "--clone-attr") == 0) {
if (argc < 4) usage();