mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-24 19:17:38 +00:00
Make sure uninstall.sh is executed on remove
This commit is contained in:
parent
493068c073
commit
8277896ca1
@ -449,6 +449,33 @@ static void prepare_modules() {
|
||||
chmod(SECURE_DIR, 0700);
|
||||
}
|
||||
|
||||
static void reboot() {
|
||||
if (RECOVERY_MODE)
|
||||
exec_command_sync("/system/bin/reboot", "recovery");
|
||||
else
|
||||
exec_command_sync("/system/bin/reboot");
|
||||
}
|
||||
|
||||
void remove_modules() {
|
||||
LOGI("* Remove all modules and reboot");
|
||||
chdir(MODULEROOT);
|
||||
rm_rf("lost+found");
|
||||
DIR *dir = xopendir(".");
|
||||
struct dirent *entry;
|
||||
while ((entry = xreaddir(dir))) {
|
||||
if (entry->d_type == DT_DIR) {
|
||||
if (entry->d_name == "."sv || entry->d_name == ".."sv || entry->d_name == ".core"sv)
|
||||
continue;
|
||||
chdir(entry->d_name);
|
||||
close(creat("remove", 0644));
|
||||
chdir("..");
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
chdir("/");
|
||||
reboot();
|
||||
}
|
||||
|
||||
static void collect_modules() {
|
||||
chdir(MODULEROOT);
|
||||
rm_rf("lost+found");
|
||||
|
@ -31,13 +31,6 @@ static void verify_client(int client, pid_t pid) {
|
||||
}
|
||||
}
|
||||
|
||||
static void remove_modules() {
|
||||
LOGI("* Remove all modules and reboot");
|
||||
rm_rf(MODULEROOT);
|
||||
rm_rf(MODULEUPGRADE);
|
||||
reboot();
|
||||
}
|
||||
|
||||
static void *request_handler(void *args) {
|
||||
int client = reinterpret_cast<intptr_t>(args);
|
||||
|
||||
@ -179,27 +172,6 @@ static void main_daemon() {
|
||||
}
|
||||
}
|
||||
|
||||
void reboot() {
|
||||
if (RECOVERY_MODE)
|
||||
exec_command_sync("/system/bin/reboot", "recovery");
|
||||
else
|
||||
exec_command_sync("/system/bin/reboot");
|
||||
}
|
||||
|
||||
int switch_mnt_ns(int pid) {
|
||||
char mnt[32];
|
||||
snprintf(mnt, sizeof(mnt), "/proc/%d/ns/mnt", pid);
|
||||
if (access(mnt, R_OK) == -1) return 1; // Maybe process died..
|
||||
|
||||
int fd, ret;
|
||||
fd = xopen(mnt, O_RDONLY);
|
||||
if (fd < 0) return 1;
|
||||
// Switch to its namespace
|
||||
ret = xsetns(fd, 0);
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int connect_daemon(bool create) {
|
||||
struct sockaddr_un sun;
|
||||
socklen_t len = setup_sockaddr(&sun, MAIN_SOCKET);
|
||||
|
@ -30,13 +30,11 @@ enum {
|
||||
DAEMON_LAST
|
||||
};
|
||||
|
||||
// daemon.c
|
||||
// daemon.cpp
|
||||
|
||||
int connect_daemon(bool create = false);
|
||||
int switch_mnt_ns(int pid);
|
||||
void reboot();
|
||||
|
||||
// socket.c
|
||||
// socket.cpp
|
||||
|
||||
socklen_t setup_sockaddr(struct sockaddr_un *sun, const char *name);
|
||||
int create_rand_socket(struct sockaddr_un *sun);
|
||||
@ -63,6 +61,7 @@ void unlock_blocks();
|
||||
void post_fs_data(int client);
|
||||
void late_start(int client);
|
||||
void boot_complete(int client);
|
||||
void remove_modules();
|
||||
|
||||
/*************
|
||||
* Scripting *
|
||||
|
@ -198,3 +198,17 @@ uint32_t binary_gcd(uint32_t u, uint32_t v) {
|
||||
} while (v != 0);
|
||||
return u << shift;
|
||||
}
|
||||
|
||||
int switch_mnt_ns(int pid) {
|
||||
char mnt[32];
|
||||
snprintf(mnt, sizeof(mnt), "/proc/%d/ns/mnt", pid);
|
||||
if (access(mnt, R_OK) == -1) return 1; // Maybe process died..
|
||||
|
||||
int fd, ret;
|
||||
fd = xopen(mnt, O_RDONLY);
|
||||
if (fd < 0) return 1;
|
||||
// Switch to its namespace
|
||||
ret = xsetns(fd, 0);
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ void init_argv0(int argc, char **argv);
|
||||
void set_nice_name(const char *name);
|
||||
int parse_int(const char *s);
|
||||
uint32_t binary_gcd(uint32_t u, uint32_t v);
|
||||
int switch_mnt_ns(int pid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user