Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Misc change
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 committed Aug 24, 2021
1 parent 3181313 commit aff578a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
7 changes: 5 additions & 2 deletions rirud/src/main/java/riru/Daemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ public class Daemon implements IBinder.DeathRecipient {
private static final String RIRU_LOADER = "libriruloader.so";

private final Handler handler = new Handler(Looper.myLooper());
private final DaemonSocketServerThread serverThread = new DaemonSocketServerThread();
private static final DaemonSocketServerThread serverThread = new DaemonSocketServerThread();

private boolean allowRestart = true;

private IBinder systemServerBinder;

static {
serverThread.start();
}

public Daemon() {
// prevent zygote died after system server starts but before onRiruLoaded called
synchronized (serverThread) {
serverThread.start();
handler.post(() -> startWait(true));
}
}
Expand Down
7 changes: 7 additions & 0 deletions rirud/src/main/java/riru/DaemonSocketServerThread.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package riru;

import static android.system.OsConstants.EINVAL;
import static riru.Daemon.TAG;

import android.net.Credentials;
Expand All @@ -24,6 +25,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -346,6 +348,11 @@ private void startServer() throws IOException {
try {
socket = serverSocket.accept();
} catch (IOException e) {
if ((e.getCause() != null && e.getCause() instanceof ErrnoException && ((ErrnoException) e.getCause()).errno == EINVAL) ||
(e.getMessage() != null && (e.getMessage().contains("EINVAL") || e.getMessage().contains(String.format(Locale.ROOT, "errno %d", EINVAL))))) {
Log.i(TAG, "Server shutdown.");
return;
}
Log.w(TAG, "Accept failed, server is closed ?", e);
return;
}
Expand Down
20 changes: 8 additions & 12 deletions rirud/src/main/java/riru/DaemonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ public class DaemonUtils {

private static final Set<Integer> zygotePid = Collections.newSetFromMap(new ConcurrentHashMap<>());

static {

public static void init(String[] args) {
magiskVersionCode = Integer.parseInt(args[0]);
magiskTmpfsPath = args[1];
if (args.length > 2) {
originalNativeBridge = args[2];
} else {
originalNativeBridge = "0";
}
try {
isSELinuxEnforcing = hasSELinux() && SELinux.isSELinuxEnabled() && SELinux.isSELinuxEnforced();
} catch (Throwable e) {
Expand Down Expand Up @@ -114,16 +120,6 @@ public class DaemonUtils {
}
}

public static void init(String[] args) {
magiskVersionCode = Integer.parseInt(args[0]);
magiskTmpfsPath = args[1];
if (args.length > 2) {
originalNativeBridge = args[2];
} else {
originalNativeBridge = "0";
}
}

public static boolean isLoaded() {
var processes = new File("/proc").listFiles((file, s) -> TextUtils.isDigitsOnly(s));
if (processes == null) {
Expand Down

0 comments on commit aff578a

Please sign in to comment.