Make sure uninstall.sh is executed on remove

This commit is contained in:
topjohnwu 2019-11-01 03:07:12 -04:00
parent 493068c073
commit 8277896ca1
5 changed files with 46 additions and 33 deletions

View File

@ -449,6 +449,33 @@ static void prepare_modules() {
chmod(SECURE_DIR, 0700); 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() { static void collect_modules() {
chdir(MODULEROOT); chdir(MODULEROOT);
rm_rf("lost+found"); rm_rf("lost+found");

View File

@ -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) { static void *request_handler(void *args) {
int client = reinterpret_cast<intptr_t>(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) { int connect_daemon(bool create) {
struct sockaddr_un sun; struct sockaddr_un sun;
socklen_t len = setup_sockaddr(&sun, MAIN_SOCKET); socklen_t len = setup_sockaddr(&sun, MAIN_SOCKET);

View File

@ -30,13 +30,11 @@ enum {
DAEMON_LAST DAEMON_LAST
}; };
// daemon.c // daemon.cpp
int connect_daemon(bool create = false); 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); socklen_t setup_sockaddr(struct sockaddr_un *sun, const char *name);
int create_rand_socket(struct sockaddr_un *sun); int create_rand_socket(struct sockaddr_un *sun);
@ -63,6 +61,7 @@ void unlock_blocks();
void post_fs_data(int client); void post_fs_data(int client);
void late_start(int client); void late_start(int client);
void boot_complete(int client); void boot_complete(int client);
void remove_modules();
/************* /*************
* Scripting * * Scripting *

View File

@ -198,3 +198,17 @@ uint32_t binary_gcd(uint32_t u, uint32_t v) {
} while (v != 0); } while (v != 0);
return u << shift; 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;
}

View File

@ -15,6 +15,7 @@ void init_argv0(int argc, char **argv);
void set_nice_name(const char *name); void set_nice_name(const char *name);
int parse_int(const char *s); int parse_int(const char *s);
uint32_t binary_gcd(uint32_t u, uint32_t v); uint32_t binary_gcd(uint32_t u, uint32_t v);
int switch_mnt_ns(int pid);
#ifdef __cplusplus #ifdef __cplusplus
} }
@ -96,4 +97,4 @@ int exec_command_sync(Args &&...args) {
bool ends_with(const std::string_view &s1, const std::string_view &s2); bool ends_with(const std::string_view &s1, const std::string_view &s2);
#endif #endif