Magisk/jni/magiskhide/main.c

65 lines
1.4 KiB
C
Raw Normal View History

2016-12-30 18:44:24 +00:00
#include "magiskhide.h"
FILE *logfile;
int i, list_size, pipefd[2];
char **hide_list = NULL, buffer[512];
pthread_t list_monitor;
pthread_mutex_t mutex;
static void terminate(int sig) {
// Close the config list monitor
pthread_kill(list_monitor, SIGQUIT);
pthread_mutex_destroy(&mutex);
// Terminate our children
i = -1;
write(pipefd[1], &i, sizeof(i));
2017-01-01 10:54:13 +00:00
exit(0);
2016-12-30 18:44:24 +00:00
}
2017-01-01 10:54:13 +00:00
int main(int argc, char *argv[]) {
2017-01-01 12:31:08 +00:00
if (argc > 1) {
2017-01-01 10:54:13 +00:00
if (strcmp(argv[1], "--daemon") == 0)
run_as_daemon();
else {
fprintf(stderr, "%s (with no options)\n\tRun magiskhide and output to stdout\n", argv[0]);
fprintf(stderr, "%s --daemon\n\tRun magiskhide as daemon, output to magisk.log\n", argv[0]);
return 1;
}
} else
logfile = stdout;
2016-12-30 18:44:24 +00:00
// Handle all killing signals
signal(SIGINT, terminate);
signal(SIGTERM, terminate);
// Fork a child to handle namespace switches and unmounts
pipe(pipefd);
switch(fork()) {
case -1:
exit(-1);
case 0:
return hideMagisk();
default:
break;
}
close(pipefd[0]);
// Start a thread to constantly check the hide list
pthread_mutex_init(&mutex, NULL);
pthread_create(&list_monitor, NULL, monitor_list, HIDELIST);
2017-01-01 10:54:13 +00:00
// Set main process to the top priority
setpriority(PRIO_PROCESS, 0, -20);
2016-12-30 18:44:24 +00:00
monitor_proc();
terminate(0);
fprintf(logfile, "MagiskHide: Cannot monitor am_proc_start, abort...\n");
fclose(logfile);
return 1;
}