mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-16 17:00:39 +00:00
Update main function
This commit is contained in:
@@ -135,3 +135,18 @@ void ps_filter_proc_name(const char *pattern, void (*func)(int)) {
|
||||
ps_filter_pattern = ((pattern == NULL) ? "" : pattern);
|
||||
ps(proc_name_filter);
|
||||
}
|
||||
|
||||
int create_links(const char *bin, const char *path) {
|
||||
char self[PATH_MAX], linkpath[PATH_MAX];
|
||||
if (bin == NULL) {
|
||||
xreadlink("/proc/self/exe", self, PATH_MAX);
|
||||
bin = self;
|
||||
}
|
||||
int ret = 0;
|
||||
for (int i = 0; applet[i]; ++i) {
|
||||
snprintf(linkpath, PATH_MAX, "%s/%s", path, applet[i]);
|
||||
unlink(linkpath);
|
||||
ret |= symlink(bin, linkpath);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@@ -46,6 +46,8 @@ int xpthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
int xsocketpair(int domain, int type, int protocol, int sv[2]);
|
||||
int xstat(const char *pathname, struct stat *buf);
|
||||
int xdup2(int oldfd, int newfd);
|
||||
ssize_t xreadlink(const char *pathname, char *buf, size_t bufsiz);
|
||||
int xsymlink(const char *target, const char *linkpath);
|
||||
|
||||
// misc.c
|
||||
|
||||
@@ -58,5 +60,6 @@ int isNum(const char *s);
|
||||
ssize_t fdreadline(int fd, char *buf, size_t size);
|
||||
void ps(void (*func)(int));
|
||||
void ps_filter_proc_name(const char *filter, void (*func)(int));
|
||||
int create_links(const char *bin, const char *path);
|
||||
|
||||
#endif
|
||||
|
@@ -226,4 +226,22 @@ int xdup2(int oldfd, int newfd) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t xreadlink(const char *pathname, char *buf, size_t bufsiz) {
|
||||
ssize_t ret = readlink(pathname, buf, bufsiz);
|
||||
if (ret == -1) {
|
||||
PLOGE("readlink %s", pathname);
|
||||
} else {
|
||||
buf[ret] = '\0';
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int xsymlink(const char *target, const char *linkpath) {
|
||||
int ret = symlink(target, linkpath);
|
||||
if (ret == -1) {
|
||||
PLOGE("symlink %s->%s", target, linkpath);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user