mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-24 15:57:37 +00:00
Fix several small issues
This commit is contained in:
parent
693848280b
commit
d66c284bed
@ -109,10 +109,9 @@ static int get_img_size(const char *img, int *used, int *total) {
|
|||||||
#define round_size(a) ((((a) / 32) + 1) * 32)
|
#define round_size(a) ((((a) / 32) + 1) * 32)
|
||||||
|
|
||||||
static int resize_img(const char *img, int size) {
|
static int resize_img(const char *img, int size) {
|
||||||
char buffer[ARG_MAX];
|
|
||||||
LOGI("resize %s to %dM\n", img, size);
|
LOGI("resize %s to %dM\n", img, size);
|
||||||
snprintf(buffer, sizeof(buffer), "e2fsck -yf %s && resize2fs %s %dM;", img, img, size);
|
snprintf(buf, PATH_MAX, "e2fsck -yf %s; resize2fs %s %dM;", img, img, size);
|
||||||
return system(buffer);
|
return system(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int merge_img(const char *source, const char *target) {
|
static int merge_img(const char *source, const char *target) {
|
||||||
@ -194,11 +193,11 @@ void exec_common_script(const char* stage) {
|
|||||||
|
|
||||||
while ((entry = xreaddir(dir))) {
|
while ((entry = xreaddir(dir))) {
|
||||||
if (entry->d_type == DT_REG) {
|
if (entry->d_type == DT_REG) {
|
||||||
snprintf(buf, PATH_MAX, "%s/%s", buf, entry->d_name);
|
snprintf(buf2, PATH_MAX, "%s/%s", buf, entry->d_name);
|
||||||
if (access(buf, X_OK) == -1)
|
if (access(buf2, X_OK) == -1)
|
||||||
continue;
|
continue;
|
||||||
LOGI("%s.d: exec [%s]\n", stage, entry->d_name);
|
LOGI("%s.d: exec [%s]\n", stage, entry->d_name);
|
||||||
char *const command[] = { "sh", buf, NULL };
|
char *const command[] = { "sh", buf2, NULL };
|
||||||
int pid = run_command(NULL, "/system/bin/sh", command);
|
int pid = run_command(NULL, "/system/bin/sh", command);
|
||||||
if (pid != -1)
|
if (pid != -1)
|
||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
@ -249,13 +248,14 @@ static char *get_full_path(struct node_entry *node) {
|
|||||||
return strdup(buffer);
|
return strdup(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Free the node and all children recursively
|
||||||
static void destroy_subtree(struct node_entry *node) {
|
static void destroy_subtree(struct node_entry *node) {
|
||||||
// Never free parent, since it shall be freed by themselves
|
// Never free parent, since it shall be freed by themselves
|
||||||
free(node->name);
|
|
||||||
struct node_entry *e;
|
struct node_entry *e;
|
||||||
vec_for_each(node->children, e) {
|
vec_for_each(node->children, e) {
|
||||||
destroy_subtree(e);
|
destroy_subtree(e);
|
||||||
}
|
}
|
||||||
|
free(node->name);
|
||||||
vec_destroy(node->children);
|
vec_destroy(node->children);
|
||||||
free(node->children);
|
free(node->children);
|
||||||
free(node);
|
free(node);
|
||||||
@ -271,7 +271,9 @@ static void insert_child(struct node_entry *p, struct node_entry *c) {
|
|||||||
vec_for_each(p->children, e) {
|
vec_for_each(p->children, e) {
|
||||||
if (strcmp(e->name, c->name) == 0) {
|
if (strcmp(e->name, c->name) == 0) {
|
||||||
// Exist duplicate, replace
|
// Exist duplicate, replace
|
||||||
destroy_subtree(e);
|
c->children = e->children;
|
||||||
|
free(e->name);
|
||||||
|
free(e);
|
||||||
vec_entry(p->children)[_] = c;
|
vec_entry(p->children)[_] = c;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -353,7 +355,8 @@ static void clone_skeleton(struct node_entry *node, const char *real_path) {
|
|||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
snprintf(buf, PATH_MAX, "%s%s", DUMMDIR, real_path);
|
snprintf(buf, PATH_MAX, "%s%s", DUMMDIR, real_path);
|
||||||
xmkdir_p(buf, 0755);
|
mkdir_p(buf, 0755);
|
||||||
|
clone_attr(real_path, buf);
|
||||||
bind_mount(buf, real_path);
|
bind_mount(buf, real_path);
|
||||||
|
|
||||||
vec_for_each(node->children, child) {
|
vec_for_each(node->children, child) {
|
||||||
@ -445,14 +448,7 @@ static void simple_mount(const char *path) {
|
|||||||
// Actual file path
|
// Actual file path
|
||||||
snprintf(buf, PATH_MAX, "%s/%s", buf, entry->d_name);
|
snprintf(buf, PATH_MAX, "%s/%s", buf, entry->d_name);
|
||||||
// Clone all attributes
|
// Clone all attributes
|
||||||
struct stat s;
|
clone_attr(buf2, buf);
|
||||||
xstat(buf2, &s);
|
|
||||||
chmod(buf, s.st_mode & 0777);
|
|
||||||
chown(buf, s.st_uid, s.st_gid);
|
|
||||||
char *con;
|
|
||||||
getfilecon(buf2, &con);
|
|
||||||
setfilecon(buf, con);
|
|
||||||
free(con);
|
|
||||||
// Finally, mount the file
|
// Finally, mount the file
|
||||||
bind_mount(buf, buf2);
|
bind_mount(buf, buf2);
|
||||||
}
|
}
|
||||||
@ -689,6 +685,7 @@ void post_fs_data(int client) {
|
|||||||
if (strcmp(hide_prop, "1") == 0) {
|
if (strcmp(hide_prop, "1") == 0) {
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
xpthread_create(&thread, NULL, start_magisk_hide, NULL);
|
xpthread_create(&thread, NULL, start_magisk_hide, NULL);
|
||||||
|
pthread_detach(thread);
|
||||||
}
|
}
|
||||||
free(hide_prop);
|
free(hide_prop);
|
||||||
}
|
}
|
||||||
@ -703,6 +700,10 @@ void late_start(int client) {
|
|||||||
write_int(client, 0);
|
write_int(client, 0);
|
||||||
close(client);
|
close(client);
|
||||||
|
|
||||||
|
// Allocate buffer
|
||||||
|
if (buf == NULL) buf = xmalloc(PATH_MAX);
|
||||||
|
if (buf2 == NULL) buf2 = xmalloc(PATH_MAX);
|
||||||
|
|
||||||
// Wait till the full patch is done
|
// Wait till the full patch is done
|
||||||
pthread_join(sepol_patch, NULL);
|
pthread_join(sepol_patch, NULL);
|
||||||
|
|
||||||
|
@ -57,9 +57,6 @@ void launch_magiskhide(int client) {
|
|||||||
|
|
||||||
hideEnabled = 1;
|
hideEnabled = 1;
|
||||||
|
|
||||||
if (init_resetprop())
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (client != -1) {
|
if (client != -1) {
|
||||||
if (setprop("persist.magisk.hide", "1"))
|
if (setprop("persist.magisk.hide", "1"))
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -277,11 +277,6 @@ int resetprop_main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PRINT_D("resetprop by nkk71 & topjohnwu\n");
|
|
||||||
|
|
||||||
if (init_resetprop())
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
return read_prop_file(filename, trigger);
|
return read_prop_file(filename, trigger);
|
||||||
} else if (del) {
|
} else if (del) {
|
||||||
|
@ -308,7 +308,7 @@ int cp_afc(const char *source, const char *target) {
|
|||||||
int clone_dir(const char *source, const char *target) {
|
int clone_dir(const char *source, const char *target) {
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
char *s_path, *t_path, *con;
|
char *s_path, *t_path;
|
||||||
|
|
||||||
if (!(dir = xopendir(source)))
|
if (!(dir = xopendir(source)))
|
||||||
return 1;
|
return 1;
|
||||||
@ -316,13 +316,8 @@ int clone_dir(const char *source, const char *target) {
|
|||||||
s_path = xmalloc(PATH_MAX);
|
s_path = xmalloc(PATH_MAX);
|
||||||
t_path = xmalloc(PATH_MAX);
|
t_path = xmalloc(PATH_MAX);
|
||||||
|
|
||||||
struct stat buf;
|
mkdir_p(target, 0755);
|
||||||
xstat(source, &buf);
|
clone_attr(source, target);
|
||||||
mkdir_p(target, buf.st_mode & 0777);
|
|
||||||
xchmod(target, buf.st_mode & 0777);
|
|
||||||
lgetfilecon(source, &con);
|
|
||||||
lsetfilecon(target, con);
|
|
||||||
free(con);
|
|
||||||
|
|
||||||
while ((entry = xreaddir(dir))) {
|
while ((entry = xreaddir(dir))) {
|
||||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||||
@ -380,3 +375,14 @@ int rm_rf(const char *target) {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clone_attr(const char *source, const char *target) {
|
||||||
|
struct stat buf;
|
||||||
|
xstat(source, &buf);
|
||||||
|
chmod(target, buf.st_mode & 0777);
|
||||||
|
chown(target, buf.st_uid, buf.st_gid);
|
||||||
|
char *con;
|
||||||
|
lgetfilecon(source, &con);
|
||||||
|
lsetfilecon(target, con);
|
||||||
|
free(con);
|
||||||
|
}
|
||||||
|
@ -88,5 +88,6 @@ int open_new(const char *filename);
|
|||||||
int cp_afc(const char *source, const char *target);
|
int cp_afc(const char *source, const char *target);
|
||||||
int clone_dir(const char *source, const char *target);
|
int clone_dir(const char *source, const char *target);
|
||||||
int rm_rf(const char *target);
|
int rm_rf(const char *target);
|
||||||
|
void clone_attr(const char *source, const char *target);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
|
||||||
@ -49,3 +50,12 @@ void vec_deep_destroy(struct vector *v) {
|
|||||||
}
|
}
|
||||||
vec_destroy(v);
|
vec_destroy(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct vector *vec_dup(struct vector *v) {
|
||||||
|
struct vector *ret = malloc(sizeof(*ret));
|
||||||
|
vec_size(ret) = vec_size(v);
|
||||||
|
vec_cap(ret) = vec_cap(v);
|
||||||
|
vec_entry(v) = malloc(sizeof(void*) * vec_cap(ret));
|
||||||
|
memcpy(vec_entry(ret), vec_entry(v), sizeof(void*) * vec_cap(ret));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -11,11 +11,14 @@ struct vector {
|
|||||||
size_t cap;
|
size_t cap;
|
||||||
void **data;
|
void **data;
|
||||||
};
|
};
|
||||||
|
|
||||||
void vec_init(struct vector *v);
|
void vec_init(struct vector *v);
|
||||||
void vec_push_back(struct vector *v, void *p);
|
void vec_push_back(struct vector *v, void *p);
|
||||||
void vec_sort(struct vector *v, int (*compar)(const void *, const void *));
|
void vec_sort(struct vector *v, int (*compar)(const void *, const void *));
|
||||||
void vec_destroy(struct vector *v);
|
void vec_destroy(struct vector *v);
|
||||||
void vec_deep_destroy(struct vector *v);
|
void vec_deep_destroy(struct vector *v);
|
||||||
|
struct vector *vec_dup(struct vector *v);
|
||||||
|
|
||||||
#define vec_size(v) (v)->size
|
#define vec_size(v) (v)->size
|
||||||
#define vec_cap(v) (v)->cap
|
#define vec_cap(v) (v)->cap
|
||||||
#define vec_entry(v) (v)->data
|
#define vec_entry(v) (v)->data
|
||||||
|
@ -285,7 +285,7 @@ if [ -f $IMG ]; then
|
|||||||
ui_print "- $IMG detected!"
|
ui_print "- $IMG detected!"
|
||||||
else
|
else
|
||||||
ui_print "- Creating $IMG"
|
ui_print "- Creating $IMG"
|
||||||
make_ext4fs -l 64M -a /magisk -S $COMMONDIR/file_contexts_image $IMG
|
make_ext4fs -l 32M -a /magisk -S $COMMONDIR/file_contexts_image $IMG
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mount_image $IMG /magisk
|
mount_image $IMG /magisk
|
||||||
|
Loading…
x
Reference in New Issue
Block a user