Skip to content

Commit

Permalink
Linux set process to kill it self when parent process dies
Browse files Browse the repository at this point in the history
  • Loading branch information
Voltstro committed Mar 16, 2024
1 parent d98d93f commit 847063d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
Expand Down Expand Up @@ -69,6 +73,13 @@ internal abstract class EngineEntryPoint : IDisposable
/// <returns></returns>
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Operations on a process or thread
/// https://www.man7.org/linux/man-pages/man2/prctl.2.html
/// </summary>
/// <param name="option"></param>
/// <param name="arg2"></param>
/// <returns></returns>
[DllImport("libc")]
public static extern int prctl(int option, ulong arg2);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../Imports/NativeDefines.props" />
<Import Project="../Imports/Properties.props" />

<PropertyGroup>
Expand Down Expand Up @@ -31,4 +32,6 @@
<ProjectReference Include="..\VoltstroStudios.UnityWebBrowser.Shared\VoltstroStudios.UnityWebBrowser.Shared.csproj" />
</ItemGroup>

<Import Project="../Imports/NatvieDefines.targets" />

</Project>

0 comments on commit 847063d

Please sign in to comment.