mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-15 22:13:11 +00:00
General QoL changes
This commit is contained in:
@@ -131,7 +131,7 @@ void node_entry::create_module_tree(const char *module) {
|
||||
auto full_path = get_path();
|
||||
snprintf(buf, PATH_MAX, "%s/%s%s", MODULEROOT, module, full_path.c_str());
|
||||
|
||||
unique_ptr<DIR, decltype(&closedir)> dir(xopendir(buf), closedir);
|
||||
auto dir = xopen_dir(buf);
|
||||
if (!dir)
|
||||
return;
|
||||
|
||||
@@ -148,7 +148,7 @@ void node_entry::create_module_tree(const char *module) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (struct dirent *entry; (entry = xreaddir(dir.get()));) {
|
||||
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
||||
if (entry->d_name == "."sv || entry->d_name == ".."sv)
|
||||
continue;
|
||||
// Create new node
|
||||
@@ -207,22 +207,18 @@ void node_entry::create_module_tree(const char *module) {
|
||||
}
|
||||
|
||||
void node_entry::clone_skeleton() {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
// Clone the structure
|
||||
auto full_path = get_path();
|
||||
snprintf(buf, PATH_MAX, "%s%s", MIRRDIR, full_path.c_str());
|
||||
if (!(dir = xopendir(buf)))
|
||||
return;
|
||||
while ((entry = xreaddir(dir))) {
|
||||
if (entry->d_name == "."sv || entry->d_name == ".."sv)
|
||||
continue;
|
||||
// Create dummy node
|
||||
auto dummy = new node_entry(entry->d_name, entry->d_type, IS_DUMMY);
|
||||
insert(dummy);
|
||||
}
|
||||
closedir(dir);
|
||||
snprintf(buf, PATH_MAX, "%s%s", MIRRDIR, full_path.data());
|
||||
if (auto dir = xopen_dir(buf); dir) {
|
||||
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
||||
if (entry->d_name == "."sv || entry->d_name == ".."sv)
|
||||
continue;
|
||||
// Create dummy node
|
||||
auto dummy = new node_entry(entry->d_name, entry->d_type, IS_DUMMY);
|
||||
insert(dummy);
|
||||
}
|
||||
} else { return; }
|
||||
|
||||
if (status & IS_SKEL) {
|
||||
file_attr attr;
|
||||
@@ -460,9 +456,8 @@ 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))) {
|
||||
auto dir = xopen_dir(".");
|
||||
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
||||
if (entry->d_type == DT_DIR) {
|
||||
if (entry->d_name == "."sv || entry->d_name == ".."sv || entry->d_name == ".core"sv)
|
||||
continue;
|
||||
@@ -471,7 +466,6 @@ void remove_modules() {
|
||||
chdir("..");
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
chdir("/");
|
||||
reboot();
|
||||
}
|
||||
@@ -479,9 +473,8 @@ void remove_modules() {
|
||||
static void collect_modules() {
|
||||
chdir(MODULEROOT);
|
||||
rm_rf("lost+found");
|
||||
DIR *dir = xopendir(".");
|
||||
struct dirent *entry;
|
||||
while ((entry = xreaddir(dir))) {
|
||||
auto dir = xopen_dir(".");
|
||||
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
||||
if (entry->d_type == DT_DIR) {
|
||||
if (entry->d_name == "."sv || entry->d_name == ".."sv || entry->d_name == ".core"sv)
|
||||
continue;
|
||||
@@ -501,7 +494,6 @@ static void collect_modules() {
|
||||
chdir("..");
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
chdir("/");
|
||||
}
|
||||
|
||||
@@ -575,15 +567,14 @@ static bool check_data() {
|
||||
}
|
||||
|
||||
void unlock_blocks() {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
int fd, dev, OFF = 0;
|
||||
|
||||
if (!(dir = xopendir("/dev/block")))
|
||||
auto dir = xopen_dir("/dev/block");
|
||||
if (!dir)
|
||||
return;
|
||||
dev = dirfd(dir);
|
||||
dev = dirfd(dir.get());
|
||||
|
||||
while((entry = readdir(dir))) {
|
||||
for (dirent *entry; (entry = readdir(dir.get()));) {
|
||||
if (entry->d_type == DT_BLK) {
|
||||
if ((fd = openat(dev, entry->d_name, O_RDONLY | O_CLOEXEC)) < 0)
|
||||
continue;
|
||||
@@ -592,7 +583,6 @@ void unlock_blocks() {
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
static bool log_dump = false;
|
||||
|
@@ -118,10 +118,10 @@ static void main_daemon() {
|
||||
|
||||
// Unmount pre-init patches
|
||||
if (access(ROOTMNT, F_OK) == 0) {
|
||||
file_readline(ROOTMNT, [](auto line) -> bool {
|
||||
file_readline(true, ROOTMNT, [](auto line) -> bool {
|
||||
umount2(line.data(), MNT_DETACH);
|
||||
return true;
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
|
||||
LOGI(SHOW_VER(Magisk) " daemon started\n");
|
||||
|
@@ -26,15 +26,14 @@ void exec_script(const char *script) {
|
||||
|
||||
void exec_common_script(const char *stage) {
|
||||
char path[4096];
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
sprintf(path, SECURE_DIR "/%s.d", stage);
|
||||
if (!(dir = xopendir(path)))
|
||||
auto dir = xopen_dir(path);
|
||||
if (!dir)
|
||||
return;
|
||||
chdir(path);
|
||||
|
||||
bool pfs = strcmp(stage, "post-fs-data") == 0;
|
||||
while ((entry = xreaddir(dir))) {
|
||||
bool pfs = stage == "post-fs-data"sv;
|
||||
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
||||
if (entry->d_type == DT_REG) {
|
||||
if (access(entry->d_name, X_OK) == -1)
|
||||
continue;
|
||||
@@ -50,13 +49,12 @@ void exec_common_script(const char *stage) {
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
chdir("/");
|
||||
}
|
||||
|
||||
void exec_module_script(const char *stage, const vector<string> &module_list) {
|
||||
char path[4096];
|
||||
bool pfs = strcmp(stage, "post-fs-data") == 0;
|
||||
bool pfs = stage == "post-fs-data"sv;
|
||||
for (auto &m : module_list) {
|
||||
const char* module = m.c_str();
|
||||
sprintf(path, MODULEROOT "/%s/%s.sh", module, stage);
|
||||
|
Reference in New Issue
Block a user