1
mirror of https://github.com/topjohnwu/Magisk synced 2024-07-11 04:07:56 +02:00

Several small tweaks

This commit is contained in:
topjohnwu 2017-11-22 16:12:08 +08:00
parent bc21a1fb71
commit f42d820891
6 changed files with 12 additions and 7 deletions

View File

@ -575,6 +575,9 @@ void post_fs(int client) {
write_int(client, 0); write_int(client, 0);
close(client); close(client);
// Allow magiskinit to full patch
close(creat(PATCHSTART, 0));
// Uninstall or core only mode // Uninstall or core only mode
if (access(UNINSTALLER, F_OK) == 0 || access(DISABLEFILE, F_OK) == 0) if (access(UNINSTALLER, F_OK) == 0 || access(DISABLEFILE, F_OK) == 0)
goto unblock; goto unblock;
@ -743,6 +746,7 @@ void late_start(int client) {
// Wait till the full patch is done // Wait till the full patch is done
while (access(PATCHDONE, F_OK) == -1) while (access(PATCHDONE, F_OK) == -1)
usleep(500); /* Wait 0.5ms */ usleep(500); /* Wait 0.5ms */
unlink(PATCHDONE);
// Run scripts after full patch, most reliable way to run scripts // Run scripts after full patch, most reliable way to run scripts
LOGI("* Running service.d scripts\n"); LOGI("* Running service.d scripts\n");

View File

@ -120,6 +120,7 @@ void auto_start_magiskhide() {
} }
void start_daemon() { void start_daemon() {
setsid();
setcon("u:r:su:s0"); setcon("u:r:su:s0");
umask(0); umask(0);
int fd = xopen("/dev/null", O_RDWR | O_CLOEXEC); int fd = xopen("/dev/null", O_RDWR | O_CLOEXEC);
@ -138,11 +139,10 @@ void start_daemon() {
struct sockaddr_un sun; struct sockaddr_un sun;
fd = setup_socket(&sun); fd = setup_socket(&sun);
if (xbind(fd, (struct sockaddr*) &sun, sizeof(sun)) == -1) xbind(fd, (struct sockaddr*) &sun, sizeof(sun));
exit(1);
xlisten(fd, 10); xlisten(fd, 10);
if ((is_restart = access(UNBLOCKFILE, F_OK) == 0)) { if ((is_restart = access(MAGISKTMP, F_OK) == 0)) {
// Restart stuffs if the daemon is restarted // Restart stuffs if the daemon is restarted
exec_command_sync("logcat", "-b", "all", "-c", NULL); exec_command_sync("logcat", "-b", "all", "-c", NULL);
auto_start_magiskhide(); auto_start_magiskhide();
@ -189,7 +189,6 @@ int connect_daemon() {
if (xfork() == 0) { if (xfork() == 0) {
LOGD("client: connect fail, try launching new daemon process\n"); LOGD("client: connect fail, try launching new daemon process\n");
close(fd); close(fd);
xsetsid();
start_daemon(); start_daemon();
} }

View File

@ -425,9 +425,9 @@ int main(int argc, char *argv[]) {
// Fork a new process for full patch // Fork a new process for full patch
setsid(); setsid();
sepol_allow("su", ALL, ALL, ALL); sepol_allow("su", ALL, ALL, ALL);
while (access(SELINUX_LOAD, W_OK) == -1) { while (access(PATCHSTART, W_OK) == -1)
usleep(500); /* Wait 0.5ms */ usleep(500); /* Wait 0.5ms */
} unlink(PATCHSTART);
dump_policydb(SELINUX_LOAD); dump_policydb(SELINUX_LOAD);
close(open(PATCHDONE, O_RDONLY | O_CREAT, 0)); close(open(PATCHDONE, O_RDONLY | O_CREAT, 0));
destroy_policydb(); destroy_policydb();

View File

@ -17,6 +17,7 @@
#define LASTLOG "/cache/last_magisk.log" #define LASTLOG "/cache/last_magisk.log"
#define DEBUG_LOG "/data/magisk_debug.log" #define DEBUG_LOG "/data/magisk_debug.log"
#define UNBLOCKFILE "/dev/.magisk.unblock" #define UNBLOCKFILE "/dev/.magisk.unblock"
#define PATCHSTART "/dev/.magisk.patch.start"
#define PATCHDONE "/dev/.magisk.patch.done" #define PATCHDONE "/dev/.magisk.patch.done"
#define DISABLEFILE "/cache/.disable_magisk" #define DISABLEFILE "/cache/.disable_magisk"
#define UNINSTALLER "/cache/magisk_uninstaller.sh" #define UNINSTALLER "/cache/magisk_uninstaller.sh"

View File

@ -16,6 +16,7 @@ const char magiskrc[] =
" rm /dev/.magisk.unblock\n" " rm /dev/.magisk.unblock\n"
" start magisk_pfsd\n" " start magisk_pfsd\n"
" wait /dev/.magisk.unblock 10\n" " wait /dev/.magisk.unblock 10\n"
" rm /dev/.magisk.unblock\n"
"\n" "\n"
// Services // Services

View File

@ -159,7 +159,7 @@ int xbind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
int xconnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { int xconnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
int ret = connect(sockfd, addr, addrlen); int ret = connect(sockfd, addr, addrlen);
if (ret == -1) { if (ret == -1) {
PLOGE("bind"); PLOGE("connect");
} }
return ret; return ret;
} }