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

View File

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

View File

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

View File

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

View File

@ -16,6 +16,7 @@ const char magiskrc[] =
" rm /dev/.magisk.unblock\n"
" start magisk_pfsd\n"
" wait /dev/.magisk.unblock 10\n"
" rm /dev/.magisk.unblock\n"
"\n"
// 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 ret = connect(sockfd, addr, addrlen);
if (ret == -1) {
PLOGE("bind");
PLOGE("connect");
}
return ret;
}