mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-26 20:47:39 +00:00
Cleanup our tracks
This commit is contained in:
parent
7188462c55
commit
43029f37b1
@ -50,6 +50,7 @@ static void *request_handler(void *args) {
|
|||||||
case LATE_START:
|
case LATE_START:
|
||||||
case BOOT_COMPLETE:
|
case BOOT_COMPLETE:
|
||||||
case SQLITE_CMD:
|
case SQLITE_CMD:
|
||||||
|
case GET_PATH:
|
||||||
if (credential.uid != 0) {
|
if (credential.uid != 0) {
|
||||||
write_int(client, ROOT_REQUIRED);
|
write_int(client, ROOT_REQUIRED);
|
||||||
close(client);
|
close(client);
|
||||||
@ -106,7 +107,7 @@ static void *request_handler(void *args) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void main_daemon() {
|
static void daemon_entry(int ppid) {
|
||||||
android_logging();
|
android_logging();
|
||||||
|
|
||||||
int fd = xopen("/dev/null", O_WRONLY);
|
int fd = xopen("/dev/null", O_WRONLY);
|
||||||
@ -118,20 +119,24 @@ static void main_daemon() {
|
|||||||
xdup2(fd, STDIN_FILENO);
|
xdup2(fd, STDIN_FILENO);
|
||||||
if (fd > STDERR_FILENO)
|
if (fd > STDERR_FILENO)
|
||||||
close(fd);
|
close(fd);
|
||||||
close(fd);
|
|
||||||
|
|
||||||
setsid();
|
setsid();
|
||||||
setcon("u:r:" SEPOL_PROC_DOMAIN ":s0");
|
setcon("u:r:" SEPOL_PROC_DOMAIN ":s0");
|
||||||
|
|
||||||
|
// Make sure ppid is not in acct
|
||||||
|
char src[64], dest[64];
|
||||||
|
sprintf(src, "/acct/uid_0/pid_%d", ppid);
|
||||||
|
sprintf(dest, "/acct/uid_0/pid_%d", getpid());
|
||||||
|
rename(src, dest);
|
||||||
|
|
||||||
// Get self stat
|
// Get self stat
|
||||||
char path[4096];
|
xreadlink("/proc/self/exe", src, sizeof(src));
|
||||||
xreadlink("/proc/self/exe", path, sizeof(path));
|
MAGISKTMP = dirname(src);
|
||||||
MAGISKTMP = dirname(path);
|
|
||||||
xstat("/proc/self/exe", &self_st);
|
xstat("/proc/self/exe", &self_st);
|
||||||
|
|
||||||
restore_rootcon();
|
restore_tmpcon();
|
||||||
|
|
||||||
// Unmount pre-init patches
|
// SAR cleanups
|
||||||
auto mount_list = MAGISKTMP + "/" ROOTMNT;
|
auto mount_list = MAGISKTMP + "/" ROOTMNT;
|
||||||
if (access(mount_list.data(), F_OK) == 0) {
|
if (access(mount_list.data(), F_OK) == 0) {
|
||||||
file_readline(true, mount_list.data(), [](string_view line) -> bool {
|
file_readline(true, mount_list.data(), [](string_view line) -> bool {
|
||||||
@ -139,13 +144,13 @@ static void main_daemon() {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
unlink("/dev/.se");
|
||||||
|
|
||||||
LOGI(NAME_WITH_VER(Magisk) " daemon started\n");
|
LOGI(NAME_WITH_VER(Magisk) " daemon started\n");
|
||||||
|
|
||||||
// Get API level
|
// Get API level
|
||||||
parse_prop_file("/system/build.prop", [](auto key, auto val) -> bool {
|
parse_prop_file("/system/build.prop", [](auto key, auto val) -> bool {
|
||||||
if (key == "ro.build.version.sdk") {
|
if (key == "ro.build.version.sdk") {
|
||||||
LOGI("* Device API level: %s\n", val.data());
|
|
||||||
SDK_INT = parse_int(val);
|
SDK_INT = parse_int(val);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -155,10 +160,10 @@ static void main_daemon() {
|
|||||||
// In case some devices do not store this info in build.prop, fallback to getprop
|
// In case some devices do not store this info in build.prop, fallback to getprop
|
||||||
auto sdk = getprop("ro.build.version.sdk");
|
auto sdk = getprop("ro.build.version.sdk");
|
||||||
if (!sdk.empty()) {
|
if (!sdk.empty()) {
|
||||||
LOGI("* Device API level: %s\n", sdk.data());
|
|
||||||
SDK_INT = parse_int(sdk);
|
SDK_INT = parse_int(sdk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LOGI("* Device API level: %d\n", SDK_INT);
|
||||||
|
|
||||||
// Load config status
|
// Load config status
|
||||||
auto config = MAGISKTMP + "/" INTLROOT "/config";
|
auto config = MAGISKTMP + "/" INTLROOT "/config";
|
||||||
@ -204,14 +209,7 @@ int connect_daemon(bool create) {
|
|||||||
LOGD("client: launching new main daemon process\n");
|
LOGD("client: launching new main daemon process\n");
|
||||||
if (fork_dont_care() == 0) {
|
if (fork_dont_care() == 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
|
daemon_entry(ppid);
|
||||||
// Make sure ppid is not in acct
|
|
||||||
char src[64], dest[64];
|
|
||||||
sprintf(src, "/acct/uid_0/pid_%d", ppid);
|
|
||||||
sprintf(dest, "/acct/uid_0/pid_%d", getpid());
|
|
||||||
rename(src, dest);
|
|
||||||
|
|
||||||
main_daemon();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (connect(fd, (struct sockaddr*) &sun, len))
|
while (connect(fd, (struct sockaddr*) &sun, len))
|
||||||
|
@ -74,7 +74,6 @@ int magisk_main(int argc, char *argv[]) {
|
|||||||
unlock_blocks();
|
unlock_blocks();
|
||||||
return 0;
|
return 0;
|
||||||
} else if (argv[1] == "--restorecon"sv) {
|
} else if (argv[1] == "--restorecon"sv) {
|
||||||
restore_rootcon();
|
|
||||||
restorecon();
|
restorecon();
|
||||||
return 0;
|
return 0;
|
||||||
} else if (argc >= 4 && argv[1] == "--clone-attr"sv) {;
|
} else if (argc >= 4 && argv[1] == "--clone-attr"sv) {;
|
||||||
|
@ -76,8 +76,11 @@ void restorecon() {
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void restore_rootcon() {
|
void restore_tmpcon() {
|
||||||
setfilecon(MAGISKTMP.data(), ROOT_CON);
|
if (MAGISKTMP == "/sbin")
|
||||||
|
setfilecon(MAGISKTMP.data(), ROOT_CON);
|
||||||
|
else
|
||||||
|
chmod(MAGISKTMP.data(), 0700);
|
||||||
|
|
||||||
auto dir = xopen_dir(MAGISKTMP.data());
|
auto dir = xopen_dir(MAGISKTMP.data());
|
||||||
int dfd = dirfd(dir.get());
|
int dfd = dirfd(dir.get());
|
||||||
|
@ -33,4 +33,4 @@ void setfilecon_at(int dirfd, const char *name, const char *con);
|
|||||||
void selinux_builtin_impl();
|
void selinux_builtin_impl();
|
||||||
void dload_selinux();
|
void dload_selinux();
|
||||||
void restorecon();
|
void restorecon();
|
||||||
void restore_rootcon();
|
void restore_tmpcon();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user