From 847063d6fa9d1f4d595077806525d8da67670155 Mon Sep 17 00:00:00 2001 From: Voltstro Date: Sat, 16 Mar 2024 22:07:19 +1000 Subject: [PATCH] Linux set process to kill it self when parent process dies --- .../Core/EngineEntryPoint.cs | 11 +++++++++ .../Native/Linux/SysPrctl.cs | 23 +++++++++++++++++++ ...udios.UnityWebBrowser.Engine.Shared.csproj | 3 +++ 3 files changed, 37 insertions(+) create mode 100644 src/VoltstroStudios.UnityWebBrowser.Engine.Shared/Native/Linux/SysPrctl.cs diff --git a/src/VoltstroStudios.UnityWebBrowser.Engine.Shared/Core/EngineEntryPoint.cs b/src/VoltstroStudios.UnityWebBrowser.Engine.Shared/Core/EngineEntryPoint.cs index e5a189f9..ece4537d 100644 --- a/src/VoltstroStudios.UnityWebBrowser.Engine.Shared/Core/EngineEntryPoint.cs +++ b/src/VoltstroStudios.UnityWebBrowser.Engine.Shared/Core/EngineEntryPoint.cs @@ -17,6 +17,10 @@ using VoltstroStudios.UnityWebBrowser.Engine.Shared.Popups; using VoltstroStudios.UnityWebBrowser.Engine.Shared.ReadWriters; +#if LINUX +using VoltstroStudios.UnityWebBrowser.Engine.Shared.Native.Linux; +#endif + namespace VoltstroStudios.UnityWebBrowser.Engine.Shared.Core; /// @@ -69,6 +73,13 @@ internal abstract class EngineEntryPoint : IDisposable /// public int Main(string[] args) { + #if LINUX + //On Linux, tell this child process to kill it self when it's parent process dies + //Option: 1 -> PR_SET_PDEATHSIG (include/uapi/linux/prctl.h) + //Arg2: 9 -> SIGKILL (arch/x86/include/uapi/asm/signal.h) + SysPrctl.prctl(1, 9); + #endif + //We got a lot of arguments //Url to start with diff --git a/src/VoltstroStudios.UnityWebBrowser.Engine.Shared/Native/Linux/SysPrctl.cs b/src/VoltstroStudios.UnityWebBrowser.Engine.Shared/Native/Linux/SysPrctl.cs new file mode 100644 index 00000000..c086a750 --- /dev/null +++ b/src/VoltstroStudios.UnityWebBrowser.Engine.Shared/Native/Linux/SysPrctl.cs @@ -0,0 +1,23 @@ +// UnityWebBrowser (UWB) +// Copyright (c) 2021-2024 Voltstro-Studios +// +// This project is under the MIT license. See the LICENSE.md file for more details. + +using System.Runtime.InteropServices; +using System.Runtime.Versioning; + +namespace VoltstroStudios.UnityWebBrowser.Engine.Shared.Native.Linux; + +[SupportedOSPlatform("Linux")] +internal static class SysPrctl +{ + /// + /// Operations on a process or thread + /// https://www.man7.org/linux/man-pages/man2/prctl.2.html + /// + /// + /// + /// + [DllImport("libc")] + public static extern int prctl(int option, ulong arg2); +} \ No newline at end of file diff --git a/src/VoltstroStudios.UnityWebBrowser.Engine.Shared/VoltstroStudios.UnityWebBrowser.Engine.Shared.csproj b/src/VoltstroStudios.UnityWebBrowser.Engine.Shared/VoltstroStudios.UnityWebBrowser.Engine.Shared.csproj index 1c570a7e..445dffd1 100644 --- a/src/VoltstroStudios.UnityWebBrowser.Engine.Shared/VoltstroStudios.UnityWebBrowser.Engine.Shared.csproj +++ b/src/VoltstroStudios.UnityWebBrowser.Engine.Shared/VoltstroStudios.UnityWebBrowser.Engine.Shared.csproj @@ -1,5 +1,6 @@ + @@ -31,4 +32,6 @@ + +