From a9aadc95df6ec51198430a986ac8f56434b25e9d Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 9 Dec 2024 09:33:08 +0100 Subject: [PATCH] Start cleanup process with setsid() Reimplement c59a3c3169973abb4ce236e06990d58ae6567481 using Os.setsid(). Refs #5613 comment Suggested-by: Simon Chan <1330321+yume-chan@users.noreply.github.com> --- server/src/main/java/com/genymobile/scrcpy/CleanUp.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java index f372855bf2..49b23e819a 100644 --- a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java +++ b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java @@ -6,6 +6,8 @@ import com.genymobile.scrcpy.util.SettingsException; import android.os.BatteryManager; +import android.system.ErrnoException; +import android.system.Os; import java.io.File; import java.io.IOException; @@ -163,6 +165,12 @@ public static void unlinkSelf() { } public static void main(String... args) { + try { + // Start a new session to avoid being terminated along with the server process on some devices + Os.setsid(); + } catch (ErrnoException e) { + Ln.e("setsid() failed", e); + } unlinkSelf(); int displayId = Integer.parseInt(args[0]);