You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Add common script support
This commit is contained in:
@@ -24,6 +24,9 @@
|
||||
pthread_t sepol_patch;
|
||||
|
||||
static void *request_handler(void *args) {
|
||||
// Setup the default error handler for threads
|
||||
err_handler = exit_thread;
|
||||
|
||||
int client = *((int *) args);
|
||||
free(args);
|
||||
client_request req = read_int(client);
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
/* late_start.c - late_start service actions
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "magisk.h"
|
||||
#include "daemon.h"
|
||||
#include "utils.h"
|
||||
|
||||
void late_start(int client) {
|
||||
LOGI("** late_start service mode running\n");
|
||||
// ack
|
||||
write_int(client, 0);
|
||||
// TODO: Do something
|
||||
close(client);
|
||||
|
||||
// Wait till the full patch is done
|
||||
pthread_join(sepol_patch, NULL);
|
||||
|
||||
// Run scripts after full patch, most reliable way to run scripts
|
||||
exec_common_script("service");
|
||||
}
|
||||
|
||||
@@ -14,8 +14,11 @@
|
||||
#include "daemon.h"
|
||||
|
||||
static void *logger_thread(void *args) {
|
||||
// Setup error handler
|
||||
err_handler = exit_thread;
|
||||
|
||||
char buffer[PATH_MAX];
|
||||
xrename("/cache/magisk.log", "/cache/last_magisk.log");
|
||||
rename("/cache/magisk.log", "/cache/last_magisk.log");
|
||||
FILE *logfile = xfopen("/cache/magisk.log", "w");
|
||||
// Disable buffering
|
||||
setbuf(logfile, NULL);
|
||||
|
||||
@@ -11,7 +11,11 @@ void post_fs(int client) {
|
||||
LOGI("** post-fs mode running\n");
|
||||
// ack
|
||||
write_int(client, 0);
|
||||
// TODO: Do something
|
||||
|
||||
// TODO: Simple bind mounts
|
||||
|
||||
close(client);
|
||||
|
||||
unblock:
|
||||
unblock_boot_process();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ static char *loopsetup(const char *img) {
|
||||
char device[20];
|
||||
struct loop_info64 info;
|
||||
int i, lfd, ffd;
|
||||
memset(&info, 0, sizeof(info));
|
||||
// First get an empty loop device
|
||||
for (i = 0; i <= 7; ++i) {
|
||||
sprintf(device, "/dev/block/loop%d", i);
|
||||
@@ -31,9 +32,18 @@ static char *loopsetup(const char *img) {
|
||||
ffd = xopen(img, O_RDWR);
|
||||
if (ioctl(lfd, LOOP_SET_FD, ffd) == -1)
|
||||
return NULL;
|
||||
strcpy((char *) info.lo_file_name, img);
|
||||
ioctl(lfd, LOOP_SET_STATUS64, &info);
|
||||
return strdup(device);
|
||||
}
|
||||
|
||||
static void *start_magisk_hide(void *args) {
|
||||
// Setup default error handler for thread
|
||||
err_handler = exit_thread;
|
||||
launch_magiskhide(-1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *mount_image(const char *img, const char *target) {
|
||||
char *device = loopsetup(img);
|
||||
if (device)
|
||||
@@ -54,15 +64,21 @@ void post_fs_data(int client) {
|
||||
char *magiskimg = mount_image("/data/magisk.img", "/magisk");
|
||||
free(magiskimg);
|
||||
|
||||
// TODO: Magic Mounts, modules etc.
|
||||
|
||||
// Run common scripts
|
||||
exec_common_script("post-fs-data");
|
||||
|
||||
// Start magiskhide if enabled
|
||||
char *hide_prop = getprop("persist.magisk.hide");
|
||||
if (hide_prop) {
|
||||
if (strcmp(hide_prop, "1") == 0)
|
||||
launch_magiskhide(-1);
|
||||
if (strcmp(hide_prop, "1") == 0) {
|
||||
pthread_t thread;
|
||||
xpthread_create(&thread, NULL, start_magisk_hide, NULL);
|
||||
}
|
||||
free(hide_prop);
|
||||
}
|
||||
|
||||
unblock:
|
||||
unblock_boot_process();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user